0

I'm running a contest where I count up all the daily comments on a webpage per unique commenter each day. At the end of the month, the person with the most comment-votes wins. I have logic written for this that worked perfectly ... until today.

When a page has more than 900 or so comments, the vote-counter stops going up. I figured this had to do with pagination, so I altered my FQL query to use LIMIT and OFFSET to parse 100 comments at a time and combine the results for my vote-counting function, but when running my queries (even by hand, putting the https://graph.facebook.com/comments url in the address bar) it craps out somewhere between 500 and 600 comments, so the last 400 or so comments on the webpage never even return!

Since this method is failing is there a more reliable way to get the comment data?

UPDATE: I'm supplying some code, but I've found the same problems persist in FQL as in the Graph API. Here's my graph API call:

https://graph.facebook.com/comments/?ids=http://www.burlesquebitch.com/article.php?id=538&limit=500

If you crank the limit to over ~600 where more than 900 comments exist (or add an offset that would put the results past that range) it begins to fail. The earlier comments disappear. When I count up the results they're somewhere between 500-600.

    https://graph.facebook.com/comments/?ids=http://www.burlesquebitch.com/article.php?id=538&limit=1000

Then I finally got fql working:

$fql_query_result =  file_get_contents("https://graph.facebook.com/fql?q=SELECT+object_id,+id,+text,+time+,+fromid+FROM+comment+WHERE+object_id='366760226746431'+LIMIT+1000");
$data = json_decode($fql_query_result,true);

It also fails, but more like around 800-900. In any case the bad behavior is the same. I even did some experiments where I limited the query by time hoping that by isolated my results to a date range I would keep myself within it's failing threshold:

$fql_query_result =  file_get_contents("https://graph.facebook.com/fql?q=SELECT+object_id,+id,+text,+time,+fromid+FROM+comment+WHERE+object_id='366760226746431'+AND+time>1365984000+AND+time<1366416000+LIMIT+500");
$data = json_decode($fql_query_result,true);

But no dice. If I flip the < to > in my time comparison the entire query fails and returns nothing. Idealy I would want to get the paging information, as suggested in the answer below, but I can't SELECT it in my query... if I try and get anything that ends in _cursor the query returns empty.

I am forced to conclude that whatever horrendous bug lives in the Graph API code its extended into the FQL code as well. I know of no other way to get data from a facebook object this size.

  • Show some code? It helps us understand and troubleshoot whatever is going on. Code speaks more than words describing it. – Jesse May 08 '13 at 02:04

1 Answers1

1

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

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

enter image description here

林果皞
  • 7,539
  • 3
  • 55
  • 70
  • I finally got this to work in general, but post_id_cursor will not get returned. I can get likes and the object_id... but nothing 'post'. I'm still trying to figure out how to page without it. – Jason Seabaugh May 09 '13 at 01:45
  • So, you can get object_id_cursor?(not object_id) You can test your app at https://developers.facebook.com/tools/explorer?method=GET&path=YOUR_APP_ID%3Ffields%3Dmigrations (Replace user access token with app access token). You should able to see all field inside migration is true. – 林果皞 May 09 '13 at 02:21
  • Yeah, to clarify... I can get object_id, but NOT object_id_cursor. I am appending an access token to my query, but it still fails while trying to get object_id_cursor... should I be using my app access token? This comment data is public, so I don't quite understand why I would need a token at all to get it. – Jason Seabaugh May 09 '13 at 03:49
  • @JasonSeabaugh App access token works fine too for this query, i tested it. Are you sure you have already enabled "July 2013 Breaking Changes"? i attached a screenshot for you. Also, you must put access token for this query, either user access token or app access token. – 林果皞 May 09 '13 at 04:15
  • I have enabled July 2013 changes and I think I generated an App Access Token from the Graph API Explorer. I am really confused about access tokens though and it's possible this is my stumbling block. I entered this GET request: https://graph.facebook.com/oauth/access_token?client_id=***my app id***&client_secret=***my app secret***&grant_type=client_credentials but it returned { "error": { "message": "Invalid callback", "type": "OAuthException", "code": 1 } } – Jason Seabaugh May 09 '13 at 15:32
  • OKay, I was able to create a 2 month app access token following steps from a nnumber of resources:https://neosmart-stream.de/facebook/how-to-create-a-facebook-access-token/ and http://itslennysfault.com/get-facebook-access-token-for-graph-api. It's a little ridiculous that I had to jump through these hoops, but I'm finally getting the object_id_cursor! – Jason Seabaugh May 09 '13 at 16:17
  • My 60-day access token ONLY works when I'm logged in, so my FQL will only work when I'm using my website... making it effectively useless for any visitor. I can get the user's access token and pass it along into my FQL, but it will fail. Apparently basic user permissions are NOT enough get object_id_cursor to return in my results... so how do I get my App Access Token to work for visitors? – Jason Seabaugh May 09 '13 at 20:33
  • More info at https://developers.facebook.com/docs/facebook-login/access-tokens/ , https://developers.facebook.com/docs/reference/dialogs/oauth/ and https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/ and http://stackoverflow.com/questions/7696372/facebook-page-access-tokens-do-these-expire – 林果皞 May 10 '13 at 03:02
  • 1. You need APP secret to get APP access token, so it's impossible you know the APP secret of Graph API Explorer app, so what you see on Graph API Explorer is User access token. 2. The 2 hours OR 2 months access token is User access token or page access token. 3. APP access token can directly use on APP_KEY|APP_SECRET form(vertical bar in the middle), Or you generate via oauth endpoint(Don't do it with Graph API explorer as answered at stackoverflow.com/questions/10508368/…) – 林果皞 May 10 '13 at 03:08
  • 4. Even though you can't generated APP access token for Graph API Explorer, but you can replace the access token text field with your APP or User access token to test. 5. You can test access token at developers.facebook.com/tools/debug. If you only see "Application ID" field, then is' a APP access token. If you able to see other info, "Scope","Expires"...etc include "Profile ID" fields, it's a page access token. If you able to see "Scope","Expires"...etc exclude "Profile ID" fields, it's a user access token. – 林果皞 May 10 '13 at 03:09