getting full number of comments of facebook status in API v2.6 - facebook

How to get number of all comments (number of status comment + number of comments of comments) without looping over every comment?
This parameters show only number of direct comments of status, without nested comments
?fields=comments.summary(true).limit(0)
How to do it similarly to FQL?
FQL requests have no problem with it
SELECT id,likes,post_fbid,time,fromid,text,text_tags,parent_id FROM
comment WHERE post_id = %post_id%
it returns all comments (nested or not) as is. easy to count and easy to check of something changed

Found an answer: you should use filter = stream
likes this
?fields=comments.summary(true).filter(stream).limit(0)
It's in the official documentation, but was not very obvious to me, that it can be used in object endpoint and not only in object/comments.
https://developers.facebook.com/docs/graph-api/reference/v2.6/object/comments#readmodifiers

Related

Facebook page rate limit - fetch post with comments and subcomments

I'd like to fetch facebook Post with comments and subcomments (lib: restfb for java)
public Post getNewPost(String postId) {
...
String fields = ".... fields ...";
Post foundPost = facebookClient.fetchObject(postId, Post.class, Parameter.with("appsecret_proof", prof), Parameter.with("fields", fields));
And it works great, fetching post and post content. My question is that 'request' costs me api call for each comment and subcomment ??
E.g
1) post -> 2 comments
By fetching this post will I use 1 api call (1 for post & content) or 3 api calls ? (1 for post & 2 for comments).
I know that graph api provide .limit(x) function, but I have to fetch post and any comment from this post with at least N history comments. And it doesn't matter if it is comment or subcomment. So I can't use until / since and limit functions.
So my 2nd question is there any way to fetch post and all comments and subcomments with only 1 api call or how to minimalize api calls.
Okay, so the answer is: it depends. You can not get unlimited amount of comments in one call, so you have to page through the comments.
To get all comments and subcomments you can use the filter=stream parameter. With this option all comments and subcomments are returned as plain list in chronological order. See here https://developers.facebook.com/docs/graph-api/reference/v2.9/object/comments/
If you only fetch one post with all comments you can fetch the Post (1 call) and then fetch the depending comments (total count comments + subcomments divided by count of elements per page). I'm not sure about the max limit you can get per page but I think it's between 200 and 500. So you can optimize the calls.
BTW you can fetch the comment count with your post and drop requesting the comments if there are none. Or you can fetch with the post the max limit of comments. Then you have to page only if there are more than max limit comments.

FQL: Get comment data WHERE object_id={a known object_id} works, but WHERE id={a known comment XID} does not?

I'm using FQL to get comment data from webpage with a Facebook comment box. I use the graph to get the object_id, then use FQL to get all comments with that object_id. However, if I want to pull data from a specific comment using its id (sometimes referred to as an XID) the FQL returns 0 results.
According to https://developers.facebook.com/docs/reference/fql/comment/ the id should be indexed, so this query should work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id={some known XID}
But it doesn't. BTW, THIS query does work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+object_id={some known object_id}
It is irritating how I can't pull query for comments using time or fromid or anything other than object_id, id, post_id, and parent_id... but in practice only using the object_id returns anything.
has anyone else run into this problem? Is my XID query wrong somehow, or is the id only indexed on certain kinds of comments, and not webpage comments for no inexplicable reason?
This one I managed to solve with trial and error. I had to put the id in single quotes. It's odd, I could query the object_id without putting it in quotes, but not the id. This is sort of what the working FQL looked like, except with a valid access token:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id='#########_####'
as opposed to:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id=#########_####
which failed to return any results.
Thanks for being consistent, Facebook :(

fb:comments-count return wrong value

I use
<fb:comments-count href=http://e-drpciv.ro/intrebare/963/></fb:comments-count>
I also try with quotes
<fb:comments-count href="http://e-drpciv.ro/intrebare/963/"></fb:comments-count>
and the return is always zero:
/**/ FB.__globalCallbacks.fdd5cbfe8aa94c({"data":[{"name":"index_link_stat_url","fql_result_set":[{"url":"http:\/\/e-drpciv.ro\/intrebare\/963\/","commentsbox_count":0}]}]});
Some other links report less comments than real.
Eg. http://e-drpciv.ro/intrebare/35 report only 3 comments
I need to update something in my code? Or is just a facebook issue and I need to wait?
This problem persist for two days.
If someone shares someone else story it wouldn't show you the comments of that previous share in your /home, but when you query the fql to get comment_count of that object "SELECT comment_info FROM photo WHERE object_id = 1234567890" it will count you all comments from all shares, this is why when you query the /home with FB API you will find posts without comments but with the SELECT ... it will return you positive number of comment's count. i belive that there is some join to make or to can get only the current user.

a unique combination of fql and graph api

am trying to search the fb posts of a given keyword but need only results with condition of having more than a specific comments count or likes count, i mean the results will only have posts which have a minimum of given value in comments count and likes count.
i tried with many developers but all are saying that its not possible, as the graph api don't offer this kind of method or http call functions.
but what my point is, there will be a possible way to mix both fql and graph and get the results, something like this, but i don't know the exact schema to use.
https://api.facebook.com/method/fql.query?format=JSON
&query=select comments from comment where object_id in
(select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/comment/')
&pretty=1
You can mix Graph API and FQL requests in a single call using batch requests. You have to use the new Graph API url instead of the REST API url you show in your question. You will also need an access_token to get this data.
Facebook does have a comments.count and a likes object for the comment FQL table. That give a numerical comment count you can query against:
SELECT comments, likes FROM comment WHERE object_id IN
(SELECT comments_fbid FROM link_stat WHERE url ='http://developers.facebook.com/docs/reference/fql/comment/')
AND (comments.count > 5 OR likes > 5)

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

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~
#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.
Graph API returns latest objects first.
Facebook provides 2 keywords to filter the fetched data.
Limit : Returns "limit" number of latest records
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.