androidfacebookfacebook-graph-apifacebook-graph-api-v2.2

Get Link to a Facebook post from API


I am struggling with getting the link to a Facebook post from an API call like this:

https://graph.facebook.com/v2.2/807247516000935/posts?access_token={TOKEN}

For most of the posts I can create the link with "www.facebook.com/" + item.getId(), but sometimes these kind of links don't work. Is there a rule how to create a link that ALWAYS works? I have the feeling that most of the links that don't work are posts, which contain a link to a Facebook post or page.

Thanks for your help!


Solution

  • The cases involved here:

    1. Using link

      If you use the link (www.facebook.com/{POST_ID}) to see the post, you will be able to see the post only if the privacy setting allows current user to see the post. Eg:

      • If privacy setting is set to PUBLIC, any one can see the post with that link
      • If privacy setting is set to ONLY ME, no one can see the post with that link etc..
    2. Using Graph API

      Unless the post is not deleted, you can query for the post details using (graph.facebook.com/{POST_ID}?access_token={ACCESS_TOKEN}) whatever be the privacy setting.

    Note: If a post is deleted by the user, obviously you wont get any details of the post by any way


    ----Edit----

    Differentiating between `photos` and `status`/`link`

    When we wish to post a link or a status message, Graph API consider this as a feed and \POST /feed is used to post it.

    And, if we wish to post a photo, \POST /photos is used.

    BUT if we want to get the posts using \GET /<ID>/feed, it gives us all the timeline posts be it link or status or photo.

    Now, if you notice carefully, the feed result has a key type, that tells you if its a link or a status or a photo. Also, if it's a photo, the API gives you another parameter: object_id which should be used to get a link to that photo.

    So-

    if type="photo"
       link="http://facebook.com/{object_id}"
    else
       link="http://facebook.com/{id}"