How do I call more than 100 statuses with Facebook API?

后端 未结 5 1177
不思量自难忘°
不思量自难忘° 2021-01-05 04:47

I\'m building a Facebook application and I want it to be able to read all the user\'s statuses from the past year. When I make the API call, I can only retrieve the first 10

5条回答
  •  爱一瞬间的悲伤
    2021-01-05 05:30

    Paging and Since, Until parameters not working for me too.

    But I found out, that I'm able get more then 100 statuses using Offset parameter. Here is my code using Facebook C# SDK:

    var fb = new FacebookClient(accessToken);
    
    string connection = "statuses";
    string urltemplate = "https://graph.facebook.com/me/{0}?limit={1}&offset={2}";
    
    int limit = 25;     //items on one page (Max is value 100)
    int offset = 0;
    
    var statuses = (IDictionary)fb.Get(string.Format(urltemplate, connection, limit, offset));
    
    while (statuses != null && statuses.ContainsKey("data") && ((Facebook.JsonArray)statuses["data"]).Count > 0)
    {
        var dataItems = (Facebook.JsonArray)statuses["data"];
    
        foreach (Facebook.JsonObject item in dataItems)
        {
            //TODO: process item data
            System.Diagnostics.Debug.WriteLine(item["message"]);
        }
    
        offset += limit;
        statuses = (IDictionary)fb.Get(string.Format(urltemplate, connection, limit, offset));
    }
    

提交回复
热议问题