2

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!

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
JensJensen
  • 1,017
  • 1
  • 12
  • 25

1 Answers1

3

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}"
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • I am using only public pages in my app. But nevertheless www.facebook.com/{POST_ID} does not work with all posts. – JensJensen Mar 10 '15 at 09:03
  • You mean that you are posting to a public page? Also, are you able to get the post using Graph API? – Sahil Mittal Mar 10 '15 at 09:08
  • I am not posting to any page. I am just resolving data from the Facebook API, display post and link to these posts. – JensJensen Mar 10 '15 at 09:21
  • If you can provide an example page/post – Sahil Mittal Mar 10 '15 at 09:39
  • Yeah, one example is this page: https://www.facebook.com/www.Christian.Weber.de. When I try to link to his last post with https://www.facebook.com/807247516000935_862717677120585 the links does not work. – JensJensen Mar 10 '15 at 09:48
  • Check the edit.. PS. in above example, the link would be: https://www.facebook.com/862715883787431 – Sahil Mittal Mar 10 '15 at 10:28
  • Thanks, I will try this later after work. But I really can't understand why Facebook does not deliver a field with an always working link to the post. – JensJensen Mar 10 '15 at 10:53