Getting embbeded Facebook comments from site

孤人 提交于 2021-02-07 10:47:15

问题


I would like to retrieve the embedded Facebook comments from the page web:

(http://www.example.com/sub_page_wFBcomments)

What I know

I can use the Facebook graph API for retrieving facebook comments directly from facebook.com. The same is not true when the comments are embedded in the web site of the facebook page's owner.

What I've tried

When using the graph API like this:

https://graph.facebook.com/v2.7/[apikey]/?key=value&access_token=[MyToken]

    {
       "link": "http://www.example.con/",
       "name": "Example.com",
       "namespace": "examplecom",
       "id": "[apikey]"
    }

And when naively adapting to the comments: [link] https://graph.facebook.com/v2.7/[apikey]/posts/?key=value&access_token=[MyToken]

It does not work, I get:

 "message": "(#100) Tried accessing nonexisting field (posts) on node type (Application)",
 "type": "OAuthException",

The facebook page has no comments/posts to show. (But when doing [apikey] = walmart, it downloads the comments of the facebook page) So I deduced something is missing: how the api would know where to look for the comments ?

How far I got:

Stackoverflow suggested to use something like /comments/?ids= "link of page" which does not work:

https://graph.facebook.com/v2.7/[apikey] /comments/?ids=http://www.example.com/sub_page_wFBcomments&access_token=[MyToken]

"message": "(#100) Tried accessing nonexisting field (comments) on node type (Application)",

remark When removing "/coments" from the previous url I recover the body in a .json, but not the comments.

Question:

Is it possible to make the api to look for the comments in ? http://www.example.com/sub_page_wFBcomments (and not from www.facebook.com/exemplecom)

Thanks for your help.

Edit

Following the @CBroe remark, I've tried the FAQ on the example

http://www.oneminuteinfo.com/2015/06/how-to-use-fb-api-to-get-fan-page-posts.html

    https://graph.facebook.com/v2.6/?fields=og_object{comments}&id=http://www.url.com&access_token=[MyToken]

    {
      "og_object": {
         "id": "1305277432850801"
      },
       "id": "http://www.oneminuteinfo.com/2015/06/how-to-use-fb-api-to-get-fan-page-posts.html"
    }

Comments missing :(

Edit 2

Thanks for the answer @TomSanders. I tried your suggestion, and it is still not working, the id I retrieved using the url is not the one that gives the comments, I explain myself:

From

https://graph.facebook.com/v2.3/[myUrl]/comments?limit=100&access_token=[myToken]

I get:

{
   "og_object": {
      "id": "813606582071724",
      "description": "the description",
      "title": "the title",
      "type": "website",
      "updated_time": "2016-10-15T16:57:59+0000"
   },
   "share": {
      "comment_count": 0,
      "share_count": 0
   },
   "id": "myUrl"
}

Remark 1 when changing the url address from http to https the "comment_count" becomes = 141.

Remark 2 using the id this request got in the next step I retrieve an empty data: {"data":[]}.

Remark 3 (!!) when right-clicking on the facebook plugin of the website I carn get the facebook id by looking for targetid = 1065663070140433. Then, when I plug it in the api I get (some of the) comments!

What am I doing wrong here? I need lights.


回答1:


Unfortunately documentation for the Facebook Open Graph API documentation is incorrect at times. Furthermore, the API has bugs that Facebook acknowledges but won't fix.

As you seem to be looking to obtain comments posted on a 3rd party website that uses the Facebook comments plugin, I would recommend that you start off by getting the object_id:

GET 'https://graph.facebook.com/v2.7/' + public_url + '?access_token=' + fb_token

Next query comments by object_id (documentation incorrectly states that you are be able to use the url as id):

GET 'https://graph.facebook.com/v2.7/' + fb_object + '/comments?access_token=' + fb_token + '&limit=100&order=reverse_chronological'

This will get you a maximum of about 9800 comments for a single object_id, even if there are more. I have not found a way to get the additional comments.

The above request for some object_ids will result in a 500 error for no apparent reason. In those cases, you can add an additional "filter=stream" filter. This will get you a maximum of 1000 comments:

GET 'https://graph.facebook.com/v2.7/' + fb_object + '/comments?access_token=' + fb_token + '&limit=100&filter=stream&order=reverse_chronological'

According to Facebook documentation, the additional filters and properties are optional. However, in practice you might get no results for a bare query, but will get results when adding the additional properties.




回答2:


To get facebook plugin comments by json you call by this url:

https://graph.facebook.com/v7.0/?id=[your url here]&fields=og_object{comments{message,from{name,%20picture}}}

Replace [your url here] with your url.

Here is an example



来源:https://stackoverflow.com/questions/39750652/getting-embbeded-facebook-comments-from-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!