How does paging work on the C# Facebook sdk

心不动则不痛 提交于 2019-12-04 23:52:14

问题


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?


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/4664197/how-does-paging-work-on-the-c-sharp-facebook-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!