Kalpesh Patel
Kalpesh Patel

Reputation: 2822

Facebook Graph API, FQL returns empty comment even though comments are present

In my one of the project, there is a functionality where user can share some articles. For sharing article, I have used following code.

  <a title="Share this answer on facebook" 
    onclick="window.open('https://www.facebook.com/sharer/sharer.php?u= 
    {URL_TO_SHARE}',
    'facebook-share-dialog','width=500,height=300'); 
    return false;">
    SHARE ON FB
   </a>

The above code absolutely works fine and shares my article to my wall. Now I want to get all comments posted on above shared link(article).

So for that, I have used following code (I am using facebook-php-sdk):

$facebook->api('/comments?id=' . $url); 
//$url is the url of the shared link which is correct

But above api calls returns empty array, even though there are comments present on this article.

I have also tried following FQL query, but that also returns empty array.

SELECT post_fbid, fromid, object_id, text, time FROM comment 
WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url = '{MY_URL}')

To cross check, I went to Explorer and checked over there. But even there also it returns empty array, as if there are no comments.

UPDATE:

For testing purpose, I have used Facebook Comment Box Plugin to my page, and posted some comment from that plugin.

Now when I fire query to Graph API, it gives me all comments posted from comment plugin. But not what I have posted from Facebook Wall.

Please suggest how can I resolve the above issue.

-- Many thanks for your time.

Upvotes: 1

Views: 1415

Answers (2)

Benjamin Hall
Benjamin Hall

Reputation: 31

Comments are associated to Facebook Graph Objects. In your above example you are actually referring to multiple open graph objects, which is part of the problem.

Object #1 is your Website Article. If you type in your Article URL into the Facebook Debugger (https://developers.facebook.com/tools/debug/) you will get information about it as Facebook has cached it into the graph store. At the bottom of this page you will see a field called Graph API. The ID in the url provided is your Graph Object ID for that page. You can even click that link to see the data for that object.

Objects #2-#n are your Shares. When your visitors "Share" the article to their timeline, they are creating a "Post" to their timeline. Each of those "Posts" has a different and unique Open Graph Object ID. The commenting plugin then attaches a unique comment board to that unique post.

Thus for one article from your website, in terms of commenting, you will have one conversation from your Website Page using the open graph object id for the article url, then a unique conversations for each post that is shared on a users stream.

It sounds like you want all of these merged together so there is only 1 commenting object.

In order to do that when you make your call to Facebook to post a comment, you have to ensure you are providing the ID of the Article Object.

Instead of this... $facebook->api('/comments?id=' . $url);

Try a POST call to: "https://graph.facebook.com/[OPEN-GRAPH-ID-OF-ARTICLE]/comments?message='my message'"

This process is outlined here: https://developers.facebook.com/docs/reference/api/using-comments/#creating

Hope this helps.

Thanks Ben

Upvotes: 1

Sebastien C.
Sebastien C.

Reputation: 2109

are you sure this website is using Facebook comments plugin? you can retrieve only those comments with the comments_fbid, and I guess only if you have the required permission (same app access)

UPDATE:

Now when I fire query to Graph API, it gives me all comments posted from comment plugin. But not what I have posted from Facebook Wall.

As I said, to retrieve comments on your Facebook Wall when you don't have the postID, you have to query Facebook to retrieve your feed, and then search inside the received posts data to find the one containing your link. Then you'll have all the comments.

Try in the graph explorer, with the request ?fields=feed. You will have an object with a feed key, and feed.data will contain an array with all your posts. For each post, look at the link property and find your link. The comments property will contain all the comments made on this facebook post.

Upvotes: 2

Related Questions