0

i want to have facebook comments + my own website comments on my site.

The thing is when showing posts i want to show a comment count next to every single one(so my comments + facebook comments). I know i can achieve this with https://graph.facebook.com/comments/?ids={PAGE_URL} but i have 100posts per page and i don't want to do this query a 100 times per page, also and more important is that i want to create a most commented widget where i currently have 1/4 of a million (250000) posts.

So basically my question is how i can access sort of a database on all comments left on my domain/site and sort them, that is manipulate them?

Kara
  • 6,115
  • 16
  • 50
  • 57
Karington
  • 253
  • 1
  • 6
  • 19

3 Answers3

3

Here are some examples of ways you could do this:

FQL:

You can build your a JSON array of queries and then use the Rest API fql.multiquery method to run them. For example, this would be your JSON array of queries:

{
  'query1': "select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/comment/')", 
  'query2': "select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/album/')"
}

Run this using the test console on the fql.multiquery page and you'll be able to see a response containing a list of post_fbids which you could then count using your favored counting method.

Graph API:

Here you can use a Batch Request to run all of your queries at once. So for a PHP Example you'd be doing:

curl \
  –F ‘access_token=…’ \
  -F ‘batch=[ \
        {“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL1}”}, \
        {“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL2}”}, \
        {“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL3}”} \
    ]’\
  https://graph.facebook.com

For as many pages as you want.

Note: Given that both APIs do have a bit of a delay before you'll get a response, obviously it's recommended to run them asynchronously so that you aren't causing your site load to delay significantly.

Community
  • 1
  • 1
Matthew Johnston
  • 4,409
  • 2
  • 20
  • 27
  • So its ok to make a for exp. cron job that does this every 15min? This would mean 250000x4(4times per hour)x24(hours in day) = 24000000 queries per day? No limit on facebook? – Karington Jul 19 '11 at 10:35
  • There are limits (you can see your apps in the Insights -> Diagnostics tab) but I'm not certain that batching counts as 1 or "n" queries. I'll try and find that out for you. – Matthew Johnston Jul 19 '11 at 17:32
  • Thanks Matthew. You the thing is for the most commented to work i need to know all of them... Unless there is a way to receive a callback every time a comment is posted or removed, which would resolve this whole issue? – Karington Jul 19 '11 at 18:15
  • So it looks like the batch queries only count as 1 single Facebook API query, you should be fine for limits on that. Also, you should consider implementing the Javascript SDK and track for the comments.create event: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ This will give you an opportunity to have your code be notified every time someone posts a comment. Thus you can probably ditch that cron job and just use the comment.create event to trigger a recount. – Matthew Johnston Jul 19 '11 at 18:32
1

Try this:

Place the URL separated by commas, If you wanna fetch multiple calls using the graph API :

https://graph.facebook.com/comments/?ids=http://URL_1,http://URL_2,http://URL_n
0

I think for your use case FQL will suit the best : https://developers.facebook.com/docs/reference/fql/comment/ . On the side note, if you wanna do multiple http calls using the graph API , its always good to do "Batch calls" as documented in the graph API documentation.

crozzfire
  • 186
  • 1
  • 1
  • 13