4

I have been trying to use Fql query to show all comments for a post.at first i show 2 posts then when 'show more comments' clicked i show next 50 comments,this way it continues.when 'show more comments' i execute following by ajax call to graph api with -

SELECT text,post_id  FROM comment  WHERE post_id=post_id limit 50

but say when i first click 'show more comments' it shows 52 comments,then when i click again it shows around 102 comments.but for next clicks 152 comments not shown.its stays in around 102 comments.

my target -

1st click to 'show more comments' = show 52 comments starting from first comments(limit value = 52 i specify in query )

2nd click = show 102 comments starting from first comments(limit value=102)

3rd click = show 152 comments starting from first comments(limit value=152) ......continues

so i am not able to achieve this.I really tried many ways using offset too.lots of problems.Are there facebook bugs? kindly help asap.

dev-m
  • 440
  • 8
  • 24

1 Answers1

5

You should try out cursor pagination, it's recommended as explained at https://developers.facebook.com/docs/reference/api/pagination/

Returned results under cursor paging more consistently match the limit requested, even after hiding any records for which you do not have permissions to view (eg. if you request 10 records, but do not have permissions to see 3 of those records, 3 additional records will be pulled transparently, so that a full 10 records are pulled).

Example with post_id_cursor:

SELECT text, post_id, post_id_cursor FROM comment WHERE post_id='22707976849_10151395520781850' ORDER BY time DESC limit 50

You get the post_id_cursor of the last comment, then navigate next page with >post_id_cursor symbol

SELECT text, post_id, post_id_cursor FROM comment WHERE post_id='22707976849_10151395520781850' AND  post_id_cursor>'Mjg3NA==' ORDER BY time DESC limit 50

Example with object_id_cursor is same:

SELECT text, post_id, object_id_cursor FROM comment WHERE object_id='10151395520696850' ORDER BY time DESC limit 50

SELECT text, post_id, time, object_id_cursor FROM comment WHERE object_id='10151395520696850' AND object_id_cursor>'Mjg3NA==' ORDER BY time DESC limit 50

Update:

Make sure you enabled "July 2013 Breaking Changes:" field at your app advanced settings, https://developers.facebook.com/apps/YOUR_APP_ID/advanced. More info at https://developers.facebook.com/roadmap

Example of get feed for certain user:

https://developers.facebook.com/tools/explorer?fql=%7B%22query1%22%3A%22SELECT%20post_id%2C%20actor_id%2C%20created_time%2C%20message%20FROM%20stream%20WHERE%20source_id%3D611693239%20AND%20created_time%3C%3Dnow()%20LIMIT%2050%20%22%2C%22query2%22%3A%22SELECT%20post_id%2C%20id%2C%20fromid%2C%20time%2C%20text%2C%20user_likes%2C%20likes%20FROM%20comment%20WHERE%20post_id%20IN%20(SELECT%20post_id%20FROM%20%23query1)%20LIMIT%205%20%22%2C%22query3%22%3A%22SELECT%20id%2C%20name%2C%20pic_square%20FROM%20profile%20WHERE%20id%20IN%20(SELECT%20actor_id%20FROM%20%23query1)%20or%20id%20IN%20(SELECT%20fromid%20FROM%20%23query2)%22%7D%0A

林果皞
  • 7,539
  • 3
  • 55
  • 70
  • 1
    Hi Thanks for reply.i tested your first query in graph api explorer and get following error - "(#602) post_id_cursor is not a member of the comment table." so how do i proceed ? – dev-m May 02 '13 at 11:13
  • Can you try this? https://developers.facebook.com/tools/explorer/?fql=SELECT%20text%2C%20post_id%2C%20post_id_cursor%20FROM%20comment%20WHERE%20post_id%3D'22707976849_10151395520781850'%20ORDER%20BY%20time%20DESC%20limit%2050%0A – 林果皞 May 02 '13 at 11:47
  • it works when i use graph api explorer token with read_stream permission.but not works when i use my application token generated for the user with same read_stream permission ! where is problem u think? my app token works well for getting feed,.... – dev-m May 02 '13 at 12:10
  • Can you go to https://developers.facebook.com/tools/explorer/?fql=SELECT%20text%2C%20post_id%2C%20post_id_cursor%20FROM%20comment%20WHERE%20post_id%3D'22707976849_10151395520781850'%20ORDER%20BY%20time%20DESC%20limit%2050%0A , paste the app access token and submit? I have no problem even i using app access token, APP_ID|APP_SECRET form – 林果皞 May 02 '13 at 12:32
  • yes i did.i generated access token by js sdk then extending it in server side by appid and secret but no luck ! is there more permission needed? – dev-m May 02 '13 at 18:05
  • You should make sure you enabled "July 2013 Breaking Changes:" field at your app advanced settings, https://developers.facebook.com/apps/YOUR_APP_ID/advanced. More info at https://developers.facebook.com/roadmap/ – 林果皞 May 03 '13 at 02:31
  • July is 2 months away and there is no change related to cursor id.so things should work now but still not getting post id cursor with my access token – dev-m May 03 '13 at 07:52
  • No, i can reproduced your issues when i disable the setting. Actually Graph API explorer should enabled it already, that's why tested with Graph API explorer no such issue. – 林果皞 May 03 '13 at 08:03
  • Now that's !! i enabled "july 13 breaking changes" in my app and generated access token by that app and using it still same problem! how to i send you personally the token you can test it? – dev-m May 03 '13 at 11:17
  • How about using app access token? App access token can directly use on APP_KEY|APP_SECRET form(combine with vertical bar, You know it right?) – 林果皞 May 03 '13 at 11:34
  • my task is like that which gets feed posts & comments of page/group.so i generated access token this way i answered in this post http://stackoverflow.com/questions/16222168/facebook-long-lived-token-not-working/16345169#16345169. Did not get "combine with vertical bar"? i got a way that after getting first 50 comments i remember last comment's time field then i get next 50 comments by this "SELECT text , post_id, time, fromid FROM comment WHERE post_id='Post_id_here' AND time > 1365696549" where 1365696549 is the time of last comment i remembered...is this error free and efficient? – dev-m May 03 '13 at 11:51
  • 1. Actually i just want to make sure your app setting is correct. Assume your app_id is ABC, and your app_secret is DEF, then you can directly using ABC|DEF as your APP Access Token without require go through oauth endpoint. 2. You should know that Time-based Pagination is not accurate as mentioned at https://developers.facebook.com/docs/reference/api/pagination/ – 林果皞 May 03 '13 at 14:12
  • K actually i am not using time based pagination by until and since parameters.i am trying comment tables time field which i think always less than next comment so that i can use it as i wrote query for that in previous messages.in that case how accurate i can get data partly? – dev-m May 03 '13 at 14:50
  • update: when i use access token as appid|secret form i see post_id_cursor.but i cant use it for security purposes.so still struggling to find out why my access token(generated by only read_stream permission) not getting cursor id – dev-m May 04 '13 at 11:45
  • That's means your app settings is correct. However, i doubt your access token is an APP access token instead of User access token, you should check the access token at https://developers.facebook.com/tools/debug/access_token. Make sure you see 'read_stream' at the "Scopes: " field – 林果皞 May 07 '13 at 02:59
  • yes i checked by debug and i see right info like App ID,UserId,Scopes: read_stream.also watch again how i generate token which i answered in this question-http://stackoverflow.com/questions/16222168/facebook-long-lived-token-not-working/16345169#16345169 so do u think its user token?? – dev-m May 07 '13 at 14:14
  • more i generated a app access token as written - http://developers.facebook.com/docs/facebook-login/access-tokens/ and it got appid|some_codes form.do u think i can use it for getting all posts/feed of page/profile/group and post comments,like,post to page wall? – dev-m May 07 '13 at 21:28
  • @professional Your one is obviously a User Access Token. App Access Token only show "Application ID: " field at debugger. Normally you should use User Access Token unless you have special requirement, because App access token have limited function compare with User Access Token. Kindly take a look at https://developers.facebook.com/docs/opengraph/howtos/publishing-with-app-token/ – 林果皞 May 08 '13 at 02:47
  • So is your APP ID is correct when debug User Access Token at debugger? So are you sure THIS APP ID's settings have enabled "july 13 breaking changes" at APP's advanced settings? Or you want to try to get User access token with https://www.facebook.com/dialog/permissions.request?_path=permissions.request&app_id=YOUR_APP_ID&redirect_uri=https://www.facebook.com/connect/login_success.html?display=page&response_type=token&perms=manage_pages,read_stream,status_update ?(replace YOUR_APP_ID) It's weird because cursor id should able to get. – 林果皞 May 08 '13 at 03:14
  • You may also test User Access Token at https://developers.facebook.com/tools/explorer/?fql=select%20column_name%2Cis_cursor%2C%20is_deprecated%2Ctype%2Cdescription%20from%20column%20where%20table_name%20%3D%20'comment' , you should able to see "column_name": "post_id_cursor" – 林果皞 May 08 '13 at 03:25
  • Hi k i have now created a new app with migration enabled.generated a access token by the user with only read_stream permission.every options of the token is correct.now when i try to get post_id comments i get post_id_cursor and others for page post.for profile post i am getting comments only which is user status or photo update by himself and not for other types of post_id i am getting for profile feed.and for group post i am not getting any comments data!! whether the group is his or of someone!.i was getting all these things before migration enabled.so what's your reasons about that?? – dev-m May 09 '13 at 12:58
  • it seems when i generate token giving "user_groups" permission too for the migration enabled app then it getting group comments!.so its look like for getting group post comments additional permission needed without only read_stream permission! is not that security risks? can anyone point out what all non risky permissions needed to get page/group/profile feed with comments with new july 2013 migration app?. – dev-m May 09 '13 at 15:56
  • I'm not sure what your means of "security risks". read_stream used on newsfeed and user_groups used on group feed. It's 2 different stuff. So you already solved your question, right? – 林果皞 May 10 '13 at 04:38
  • Have not found yet what permissions needed to get profile feed posts comments.if those are risky? So am i right that after migration there are additional permissions needed than read_stream to get group and profile feed posts with comment? – dev-m May 10 '13 at 07:37
  • No, you must granted user_groups permission to get group feed, it's not related to migration. I mentioned migration because it would allow us to do cursor pagination. – 林果皞 May 10 '13 at 09:17
  • but before migration i was getting comments for group/page/profile feed posts without user_groups permission but after migration i am not getting comments for any group/profile posts!. to get group post comments i had to include user_groups permission. – dev-m May 10 '13 at 10:48
  • I tested whether or not i enable or disable "July 2013 Breaking Changes:", i still need user_groups. I test with CLOSED group, i wouldn't able to query graph.facebook.com/GROUP_ID if i didn't granted user_groups. Whatever, its supposed to be, otherwise what is the purpose of user_groups? – 林果皞 May 10 '13 at 11:05
  • anyway after i granted user_groups permission when migration enabled, i can get any group feed post's comments!.do u have any ideas what other permissions i need to get profile feed posts with 'comments'? – dev-m May 10 '13 at 11:23
  • I think you are asking something as answered by me at http://stackoverflow.com/questions/16336261/new-facebook-api-fetching-newsfeed-and-its-comments/16338033#16338033. Please note, this answer doesn't include cursor. – 林果皞 May 10 '13 at 11:30
  • not actually.your that answer solves to get user's home page feed where the access token must be of that user.but i want to get any user's public feed by any user's access token this way - graph.facebook.com/user_id/feed. – dev-m May 10 '13 at 12:08
  • @professional The only different is you need using source_id(feed) instead of uid(newsfeed). I edited my answer. The only drawback is it's doesn't support cursor on this query. – 林果皞 May 10 '13 at 12:27
  • did you mean i place source_id in your query here - http://stackoverflow.com/questions/16336261/new-facebook-api-fetching-newsfeed-and-its-comments/16338033#16338033 as source_id not allowed.let me tell you what query i use - {'query1':'SELECT post_id,comment_info FROM stream WHERE source_id=id_here limit "+ o.max +"','query2':'SELECT post_id,fromid,text,time,likes FROM comment WHERE post_id IN(SELECT post_id FROM #query1)','query3':'SELECT name,uid FROM user WHERE uid IN(SELECT fromid FROM #query2)'} – dev-m May 10 '13 at 13:00
  • @professional You got error? i have no problem with your query https://developers.facebook.com/tools/explorer?fql=%7B'query1'%3A'SELECT%20post_id%2Ccomment_info%20FROM%20stream%20WHERE%20source_id%3D%3D611693239%20limit%2050'%2C'query2'%3A'SELECT%20post_id%2Cfromid%2Ctext%2Ctime%2Clikes%20FROM%20comment%20WHERE%20post_id%20IN(SELECT%20post_id%20FROM%20%23query1)'%2C'query3'%3A'SELECT%20name%2Cuid%20FROM%20user%20WHERE%20uid%20IN(SELECT%20fromid%20FROM%20%23query2)'%7D – 林果皞 May 10 '13 at 13:05
  • no but no comments return as we are discussing that long time.did u get what problem i am having?.in case of profile my access token with only read_stream permission not getting comments of profile posts by the above query in my previous message.plz read again all my previous messages for problems i facing – dev-m May 10 '13 at 13:15
  • @professional i granted read_stream only and i'm able to get this comment "hapi Bday" at https://www.facebook.com/611693239/posts/561221737225939 with https://developers.facebook.com/tools/explorer?fql=%7B'query1'%3A'SELECT%20post_id%2Ccomment_info%20FROM%20stream%20WHERE%20source_id%3D611693239%20limit%2050'%2C'query2'%3A'SELECT%20post_id%2Cfromid%2Ctext%2Ctime%2Clikes%20FROM%20comment%20WHERE%20post_id%20IN(SELECT%20post_id%20FROM%20%23query1)'%2C'query3'%3A'SELECT%20name%2Cuid%20FROM%20user%20WHERE%20uid%20IN(SELECT%20fromid%20FROM%20%23query2)'%7D – 林果皞 May 10 '13 at 13:35
  • k this is my a status https://www.facebook.com/Mridulcs/posts/508640225859247 my profile id - 100001398224811 try it giving as source_id and let me know u see comment?! – dev-m May 10 '13 at 13:42
  • @professional I think it's a API bug, you should report the bug at https://developers.facebook.com/bugs/create. You can complain that you need user_groups permissions to query graph.facebook.com/100001398224811_483601645028750/comments using Graph API Explorer, which the post is not a group post. – 林果皞 May 10 '13 at 14:25
  • I tried create bug but it showing me error that app id is empty though i entered.so create one that i have to give user_groups permission to get group post's comments whether group is mine or someones and let me know – dev-m May 11 '13 at 16:50