简体   繁体   English

使用Graph API检索Facebook帖子评论

[英]Retrieve Facebook Post Comments Using Graph API

I tried to get Facebook comments using: 我尝试使用以下方式获取Facebook评论:

http://graph.facebook.com/[post_id]/comments

It results only 2 of 15 comments, and without count info. 它仅产生15条评论中的2条,并且没有count信息。

{
    "data": [
        {
            "id": "[post_id]",
            "from": {
                "name": "[name]",
                "id": "[id]"
             },
             "message": "[message]",
             "created_time": "2011-01-23T02:36:23+0000"
        },
        {
             "id": "[id]",
             "from": {
             "name": "[name]",
                 "id": "[id]"
             },
            "message": "[message]",
            "created_time": "2011-01-23T05:16:56+0000"
        }
    ]
}

Anyone know why only 2 comments? 有谁知道为什么只有2条评论?

Also, I want to retrieve comments (default number) or retrieve comments with my limit number, and get its comments count. 此外,我想检索注释(默认编号)或检索带有我的限制编号的注释,并获取其注释计数。 Any idea? 任何的想法? (Please use Graph API). (请使用Graph API)。

You need to call it from a secure request https and provide an access_token : 您需要从安全请求https调用它并提供access_token

https://graph.facebook.com/19292868552_118464504835613/comments?access_token=XXX

EDIT: 编辑:
Added the object from the post document. 添加了post文档中的对象。 try clicking the comments connection and then remove the access_token and try and see the difference. 尝试单击comments连接,然后删除access_token并尝试查看差异。

In order to get the Like count and the comment count then you need to use a combination of the PostOwnerID and PostID not just the PostID 为了获得Like计数和comment计数,您需要使用PostOwnerIDPostID的组合而不仅仅是PostID

So for your example it would be: 所以对于你的例子,它将是:

https://graph.facebook.com/153125724720582_184234384932460/comments

Again, as mentioned in some of the other answers you need to use the https method along with an auth_token 同样,正如其他一些答案中所提到的,您需要使用https方法和auth_token

I experienced the same problem with comments. 我对评论遇到了同样的问题。 The issue was that I was using an access token for a test user. 问题是我正在为测试用户使用访问令牌。 Because test users don't have access to other FB users information, only the comments from pages were shown. 由于测试用户无权访问其他FB用户信息,因此仅显示来自页面的注释。

There is a word JUGAAR in Urdu that means, finding a way out, just to get the job done. 在乌尔都语中有一个单词JUGAAR意味着找到出路,只是为了完成工作。 So for like purpose I made this JUGAAR, I hope it helps. 所以出于同样的目的我制作了这个JUGAAR,我希望它有所帮助。

$contents = file_get_contents("http://graph.facebook.com/" . $_GET['id'] . "/likes");
if (substr_count($contents, 'name')>0) {
    echo substr_count($contents, 'name') . " people like this album";
}

By the way I am also new to this Fb stuff, I am looking for help to post comments. 顺便说一句,我也是这个Fb的新手,我正在寻找帮助发表评论。 When I try to use graph.api./id/comments?access_token=sdfsfsdf&message="D" it still returns comments for the id instead of posting. 当我尝试使用graph.api./id/comments?access_token=sdfsfsdf&message="D“时,它仍会返回id的注释而不是发布。

As a sanity check, do you have "read_stream" permission? 作为完整性检查,您是否拥有“read_stream”权限? I can see the full comments with my access token that uses "read_stream". 我可以看到使用“read_stream”的访问令牌的完整注释。 As mentioned by other people, you have to use https and access token as well... 正如其他人所提到的,你必须使用https和访问令牌......

It results only 2 of 15 comments 它只有15条评论中的2条

Add a limit parameter to the URL: 向URL添加限制参数:

 http://graph.facebook.com/[post_id]/comments?limit=1000&access_token=XXX

This should show all the comments. 这应该显示所有评论。

After Successfully Login call this method facebookComments() 成功登录后调用此方法facebookComments()

parameters.putString("fields", "message"); parameters.putString(“fields”,“message”); .............// Its Important .............// 这一点很重要

 AccessToken accessToken = AccessToken.getCurrentAccessToken();
    public void facebookComments() {
        try {
            getFriends(accessToken, new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {
                            Log.e("keshav", "one" + response);
                            CommonMethod.showAlert("res  --> " + response, MainActivity.this);
                        }
                    }
            );
        } catch (Exception e) {
            CommonMethod.showAlert("Exception is -> " + e, MainActivity.this);
        }
    }

    public void getFriends(AccessToken token, GraphRequest.Callback callback)
    {
        // TODO Comments Working but id return only
        GraphRequest requestt = new GraphRequest(token, "744511125731315_751199848395776/comments",
                null, HttpMethod.GET, callback);
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id");           // todo in use imp
        parameters.putString("fields", "name");           // todo in use imp
        parameters.putString("fields", "from");           // todo in use imp
        parameters.putString("fields", "message");           // todo in use imp
        requestt.setParameters(parameters);
        requestt.executeAsync();
    }

尝试通过App Login(http://developers.facebook.com/docs/authentication)进行身份验证,然后使用access_token prarameter调用GraphAPI。

You can do something like this to avoid the whole count of comments issues: 您可以执行以下操作以避免整个评论问题:

  1. Get the object's ( a post is considered an object in the Graph API ) ID-as I understand from your question, you already have it? 获取对象( 帖子被认为是Graph API中的对象 )ID - 我从您的问题中了解到,您已经拥有它了吗?
  2. Create a Comments Social Plugin with this ID, and get the code for it. 使用此ID创建一个评论社交插件 ,并获取它的代码。
  3. Embed the code in your site. 将代码嵌入您的网站。

This will result in all the comments for this object. 这将导致此对象的所有注释。

To get the count of comments per object, you can execute an fql query , something like this: 要获取每个对象的注释计数,可以执行fql查询 ,如下所示:

SELECT comments FROM stream WHERE post_id = [yourpostid]

This will return in the comments array under the count parameter the number of counts for this object. 这将在count参数下的comments数组中返回此对象的计数数。

SELECT comments FROM stream WHERE post_id = [yourpostid] shall not work in this case .. SELECT comments FROM stream WHERE post_id = [yourpostid]在这种情况下不起作用..

the id which is returned after making a graph call successfully to post on a user's wall (using access_token of an application ) is of the form abcdef_qwerty ( underscore seperated id ) where as the post id which is mapped in the post_id of the comments table is of the form "lmnop" .. 在成功调用图形以在用户的​​墙上发布(使用应用程序的access_token)后返回的id的形式为abcdef_qwerty(下划线分隔id),其中post id在map表的post_id中映射为形式“lmnop”..

to get the counts of like and comments on this post id of form "abcdef_qwerty" making a graph call withh app generated access token seems to be the only solution .. 得到喜欢的评论和评论这个帖子id的形式“abcdef_qwerty”使用app生成的访问令牌进行图形调用似乎是唯一的解决方案..

something like: https://graph.facebook.com/100002619172565_117323155031656?access_token=xxxxxxxxxxxxx 类似于: https//graph.facebook.com/100002619172565_117323155031656?access_token = xxxxxxxxxxxxxx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM