How can I post new comment with Graph API into Social Comments Box?

前端 未结 3 581
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 18:25

I have facebook social comments box. How can I post comment through graph API to it?

相关标签:
3条回答
  • 2020-12-03 18:53

    Its very easy as you post on user feed after getting access_token with publish stream token

    I assume you use PHP SDK if you need in other let me known

    You just need Step 4 but i give you more details in Step 1 to 3 so you can understand and do clearly

    Step 1

    get the user access token

            $token = $facebook->getAccessToken();
            echo "</br>" . 'Access_Token:' . $token;
    

    Step 2
    set default access token and profile

            $facebook->setAccessToken($token);
    

    Step 3
    compile the post

        $WallPost = array(
        'message' => 'hey this app is cool!!',
        'link' => $canvas_page,
        'caption' => 'caption',
        'description' => 'Test Description',
                );  // you can also use 'picture', 'description', 'source'.... 
    

    Step 4
    post to wall or your Social Comment Plugin

            $response = $facebook->api('/me' . '/feed','POST',$WallPost);
    

    Thanks

    0 讨论(0)
  • 2020-12-03 18:54

    Seems that it is not possible, and will never be:

    This functionality was never and is not intended to be available.

    An error message has been added for this case: "Comments may not be added to a comment plugin"

    https://developers.facebook.com/bugs/164794086987157

    0 讨论(0)
  • 2020-12-03 19:04

    I can give you half the answer to this question, but still need the other half very much myself. You can post a reply to an existing comment within Social Comments box by finding its post_fbid. To get this you can use FQL such as:

    https://api.facebook.com/method/fql.query?query=SELECT post_fbid, id FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url ='[ PAGE_URL ]')&access_token=[ ACCESS_TOKEN ]
    

    This query will need to be run through an escape() with the PAGE_URL and then used for an HTTP GET request:

    https://api.facebook.com/method/fql.query?query=SELECT%20post_fbid%2C%20id%20%0A%20%20%20%20%20%20%20%20FROM%20comment%20%0A%20%20%20%20%20%20%20%20WHERE%20object_id%20IN%20%0A%20%20%20%20%20%20%20%20%20%20(SELECT%20comments_fbid%20%0A%20%20%20%20%20%20%20%20%20%20%20FROM%20link_stat%20%0A%20%20%20%20%20%20%20%20%20%20%20WHERE%20url%20%3D'http%3A%2F%2Fexample.com')&access_token=[ ACCESS_TOKEN ]
    

    With the post_fbid you can make a reply by doing an HTTP POST to:

    https://graph.facebook.com/[ POST_FBID ]/comments/?access_token=[ ACCESS_TOKEN ]&message=[ MESSAGE]
    

    Now for posting a new comment to the page this used to work until recently with an HTTP POST:

    http://graph.facebook.com/comments/?ids=[ PAGE_URL ]&access_token=[ ACCESS_TOKEN ]&message=[ MESSAGE]
    

    But currently this is consistently returning:

    {
      "error": {
        "message": "An unknown error has occurred.", 
        "type": "OAuthException"
      }
    }
    

    I hope this helps a bit and if anyone can shed some light if posting a new comment like this is even possible anymore it would be greatly appreciated.

    0 讨论(0)
提交回复
热议问题