Sharon
Sharon

Reputation: 3919

How can I retrieve all comments on a Facebook post using the php SDK?

I'm building an app which allows users to post articles to their facebook wall. When an article is posted, I retrieve the post id and store that in the database along with the rest of the article details. Now I want to be able to show the comments made on that post when someone views the article in my site; I would also like to allow users to add comments to the post from my site.

I know that the user is always logged into Facebook when they are viewing the article, as the system checks for that earlier on.

I've been using the PHP SDK, and thought all I had to do was something like:

$post_comments = $facebook->api('/' . $post_id . '/comments');

However, when I do this, I get the following error:

Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /APP_PATH/facebook/src/facebook.php on line 560

I really don't have much of a clue what I'm doing here, to be honest, as I'm very new to the Facebook Graph API, and I can't seem to find a lot of documentation on it.

Can anyone tell me what I should be doing here, or point me to some documentation I could read about it?

Thanks!

Upvotes: 2

Views: 3395

Answers (2)

AjayR
AjayR

Reputation: 4179

It should work.

Here is the code I am using which is working for me.

$comments = $facebook->api($postid . '/comments');

Make sure your postid is a valid one.

Alternatively, you can directly type that url in browser to get details like this https://graph.facebook.com/<postedid>/comments

Please refer this link for further reference http://developers.facebook.com/docs/reference/api/Comment/

Upvotes: 1

zopieux
zopieux

Reputation: 2901

I don't know what your PHP library is doing, but you can actually access comments by reading graph.facebook.com/<post_id>/comments. Indeed, try with this one from the doc.

Are your sure of your post id? Try to call the buggy function with 19292868552_118464504835613 as post id. It has to work.

Upvotes: 1

Related Questions