facebookfacebook-graph-apifacebook-graph-api-v2.2

how to programmatically post a comment on Facebook post


I am noob to Facebook api, let me explain this in more detail, I have gone through graph api, I am able to post a comment using correct access token via graph explorer, all works fine.

my question is that I see a post on Facebook wall, I want my app to post a comment on this post, how does my app know the post_id of this post, are there any ways to get post id of latest post, or for last 10 posts or some other way.

thanks in advance


Solution

    1. To read the recent feeds of a user-

      \GET /<user-id>/feed
      

      with this, you'll get the posts and their details (id, objectid, type message, description etc.) You can use the Graph API Explorer to check.

    2. To post a comment on a post-

      \POST /<object-id>/
      message=This+is+a+test+comment
      attachment_url=.....
      

      object-id be the object-id for photos and id for feeds.

    You can go through the API Reference to see what all APIs are available.