facebook graph api comment list sort , like 'orderby=desc'?
Asked Answered
I

2

13

I use graph api to get the picture's comments, but I want to first sort the results by creating time and then return to the latest data. Similar to the sql statement 'order by create_time desc', I do not know if have such a parameter.

Currently used to offset and limit access to the latest data, but also know the total number of comments,

pagesize = 25;
offset = comments.count - pagesize;
limit = 25;

url = "https://graph.facebook.com/" + object_id + "/comments?access_token=" + access_token + "&limit=" + limit + "&offset=" + limit;

next page:

offset -= 25

but comments.ount of numerical sometimes is not accurate

and the result of the request URL to return to sometimes don't match

Whether to have very good solution

Or I used the wrong way (‘limit’ and ‘offset’ Parameter)!!!


Thank you for your answer.

"Graphics API" the existence of the cache?

i post a message and 46 comments.requests url, set the parameters:

offset=0&limit=1

Then it should return to the last comment (latest one), the actual return to the middle of a comment, and I tested a few times, set the offset and limit. According to the returned results, the middle one is the latest comment

If I set the limit value is greater than the 'comment.count', the returned data is all, the official website and facebook consistent

Because the cache reason?

Thanks again~

Ice answered 12/10, 2011 at 15:26 Comment(4)
why don't you use FQL? seems like more flexible in this case.Dionysus
fql~ SELECT object_id, text, time FROM comment WHERE object_id = 'object_id' order by time desc Indeed very flexible, but "graph api" does not it? I can only use it~. 'fql' is a "Graph api" ? If that would be too nice~!Ice
graph API doesn't have WHERE and ORDER BY so in your case FQL seems more flexible. FQL is a feature of graph since it performs queries on graph objects and connections.Dionysus
This has become important again as FQL seems to be deprecated. developers.facebook.com/docs/reference/fqlMockingbird
B
5

@dbau - You are still better off using FQL. In my experience, unless you are making a very simple call, you have very little control over what you get via a Graph API call.

Why don't you want to use FQL? FQL is an endpoint of the Graph API. There is still some data that can only be returned via FQL.

This will get you the result you're looking for. The query needs to be URL encoded. I left it in plain text for clarity.

 https://graph.facebook.com/fql?access_token=[TOKEN]&q=
    SELECT id, fromid, text, time, likes, user_likes FROM comment
      WHERE object_id = [OBJECT_ID] ORDER BY time DESC LIMIT 0,[N]

You may find you don't get [N] comments returned each time, because Facebook filters out items that are not visible to the access_token owner after the query is run. You could either up the LIMIT and filter out any excess results returned or if you are using a user access_token, you could add AND can_like = TRUE to the WHERE clause to be guaranteed that, if they exist, [N] posts visible to the current user are returned.

Boudicca answered 4/8, 2012 at 3:43 Comment(0)
A
3

Graph API returns latest objects first.

Facebook provides 2 keywords to filter the fetched data.

  1. Limit : Returns "limit" number of latest records
  2. Offset : Returns "limit" number of records from the offset position

So to retrieve latest "x" comments posted for an object

https://graph.facebook.com/[OBJECTID]?limit=[X]&offset=0

To retrieve next "X" comments (page wise)

https://graph.facebook.com/[OBJECTID]?limit=[X]&offset=[X*PAGENo]

Hope the answer is clear enough for you.

Aliquot answered 12/10, 2011 at 16:13 Comment(6)
thank you for your answer. "Graphics API" the existence of the Cache?Ice
Is this still the case? offset=0 seems to refer to the oldest comment while offset=1...n returns later comments for me!Fortuneteller
See my updated answer. Facebook GRAPH API retrieves latest records first by default and same is the case with the normal Facebook website. So offset zero retrieves the most latest "LIMIT" number of recordsAliquot
Is there a way to reverse the order so you get the oldest ones first?Irrepressible
The claim that Graph API returns items newest-first is SimplyNotTrue™ at least in the case of comments on a photo, and possibly in a few other cases. These are always returned oldest-first, and the "until" modifier is flatly ignored.Borrero
Retrieving photos from the Graph API also returns oldest-first.Sacring

© 2022 - 2024 — McMap. All rights reserved.