iosfacebook-graph-apifacebook-ios-sdkfbconnect

Facebook connect graph status objects have comments capped at 25


Does anyone know why no matter how many comments a given graph status update object has, it will cap the comments at 25? I have a feeling it only returns a 'sample' of the actual comments on the object. How do I force it to get them all without using the FQL APIs?


Solution

  • This is just the way the Graph API works. Take a look at the API docs. You get 25 at a time and have to loop through them. You can use the timestamp (created_time) of the last comment in the batch as a parameter in the next Graph API call or you can use the offset parameter. Which is what I've been doing. I was running into some screwiness using created_time. This is an example from my C# test app. Ignore the references to the PostComment object that's just a data structure I created to hold the data I'm pulling. The magic (and the process i'm referencing) is in the parameters being passed to the graph API call:

    parameters.Add("offset", numPostComments);
    parameters.Add("limit", 25);
    

    I'm fairly certain you can set the "limit" to anything 25 or below.

    do
    {
        foreach (var comment in comments.data)
            {
                numPostComments++;
                PostComment pc = new PostComment();
                pc.Post_ID = p.Id;
                pc.Facebook_ID = comment.id;
                pc.From = comment.from.name;
                if (comment.likes != null)
                    pc.Likes = (int)comment.likes;
                pc.CommentDate = DateTime.Parse(comment.created_time);
                pc.CommentText = comment.message;
                p.Comments.Add(pc);
            }
            // Create new Parameters object for call to API
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("offset", numPostComments);
            parameters.Add("limit", 25);
    
            // Call the API to get the next block of 25
            comments = client.Get(string.Format("{0}/comments", p.Facebook_ID), parameters);
    } while (comments.data.Count > 0);