Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does paging work on the C# Facebook sdk

Cannot find any documentation for this...

Currently using the following code to get a list of my photos:

FacebookApp fb = new FacebookApp(accessToken);
dynamic test = fb.Get("me/photos");

I'm cycling through the first 25 photos that it returns. Simple.

Now how do it get it to return the next 25?

So far I've tried this:

FacebookApp fb = new FacebookApp(accessToken);
string query = "me/photos";

while (true)
{
    dynamic test = fb.Get(query);

    foreach (dynamic each in test.data)
    {
        // do something here
    }

    query = test.paging.next;
}

but it fails throwing:

Could not parse '2010-08-30T17%3A58%3A56%2B0000' into a date or time.

Do I have to use a fresh dynamic variable for every request, or am I going about this the wrong way completely?

like image 706
Tim Avatar asked Jan 12 '11 00:01

Tim


2 Answers

Ended up finding this:

// first set (1-25)
var parameters = new ExpandoObject();
parameters.limit = 25;
parameters.offset = 0;

app.Api("me/friends", parameters);

// next set (26-50)
var parameters = new ExpandoObject();
parameters.limit = 25;
parameters.offset = 25;

app.Api("me/friends", parameters);
like image 90
Tim Avatar answered Oct 15 '22 18:10

Tim


I also found you can use this.

// for the first 25 albums (in this case) 1-25
dynamic albums = client.Get("me/albums", new { limit = "25", offset = "0"});

// for the next 25 albums, 26-50
dynamic albums = client.Get("me/albums", new { limit = "25", offset = "25"});

Worked the same as you used above.

like image 27
Andy Avatar answered Oct 15 '22 19:10

Andy