Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API: Find graph object from post URL

Given the URL of a public Facebook post, how can one find the post object in the FB Graph API? (secondarily, why are so many user feeds empty or nearly empty when accessed through the API?)

We would like to be able to comment on or like a post via the v2.x Graph API, given the post's URL. Doing so requires the post's object ID, which we can make some educated guesses about, but accessing the actual object through the API has proven unreliable (works for some posts but not others).

v2 of the API introduced app-scoped user IDs, and post IDs generally seem to be of the form {app-scoped user id}_{unique post id}. Here are the details of some attempts to find posts in the API with various combinations of these IDs (global user id, app-scoped user id, and post id).

  • Starting with a simple example: https://www.facebook.com/evan.prodromou/posts/10153023417510505. Key characteristics are that it's public, it's not a share of another post, and most importantly it has no photo(s), which add extra ids and URLs for the individual photo(s) and photo set. Evan's profile is also public, i.e. https://www.facebook.com/evan.prodromou doesn't show the generic This content is currently unavailable

  • Trying the bare post id from that URL, /v1.0/10153023417510505 and /v2.2/10153023417510505 both give the Unsupported get request (code 100) error.

  • Evan's global user id is 525575504. Attaching that as a prefix, /v1.0/525575504_10153023417510505 and /v2.2/525575504_10153023417510505 still both give the same Unsupported get request error.

  • Same error using his app-scoped user id instead, /v2.2/10152350676805505_10153023417510505.

OK let's try the other direction. We'll page through the user's feed until we find the post in question. It feels like this is more the expected use case for the API...

  • Both the global /v2.2/525575504/posts and app-scoped /v2.2/10152350676805505/posts return nothing, but /v1.0/525575504/posts returns two recent posts, this like and this post. Not sure why only those two, even though has plenty of other recent public posts. The like is fetchable via its id field in both api versions, i.e. /v1.0/525575504_10153045879215505 and /v2.2/10152350676805505_10153045879215505, but both API versions return the Unsupported get request error when fetching the post via its id field, e.g. /v1.0/525575504_351575675029953 and /v2.2/10152350676805505_351575675029953

  • Trying another public post, this one with pictures: https://www.facebook.com/andigalpern/posts/678121182314631 . /v1.0/100003502653187_678121182314631, /v2.2/100003502653187_678121182314631, and /v2.2/499657186827699_678121182314631 all error.

  • /v1.0/100003502653187/posts only includes one post, a like, and /v2.2/100003502653187/posts is empty.

For reference, here is the GitHub issue where we have been tracking this problem.

like image 424
kylewm Avatar asked Feb 05 '15 06:02

kylewm


People also ask

Can you still graph search on Facebook?

In early June 2019, the feature was further deprecated, with the majority of URLs for graph search queries no longer working. Facebook explained this by saying: "The vast majority of people on Facebook search using keywords, a factor which led us to pause some aspects of graph search and focus more on improving keyword ...

What can I do with Facebook Graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

Is Facebook Graph API a REST API?

Yes, it is a REST API as well. Show activity on this post. Yes, there have been 3 Facebook API's to date: Legacy REST.


1 Answers

Basically you would need read_stream for this (which your app will not get granted). And yes, even though the post is public, you still need read_stream to be able to get read access to all kinds of posts.

You can easily play around with this in Graph API Explorer. First give your app read_stream permission to get ids of items in your feed – that will give you ids of the “form app-scoped user id underscore post id”. Then remove read_stream (by clicking “Get Access Token” again and using the “Clear” button), and try several of the user_* permissions – and you will see that for most of your posts, even the public ones, you will still only get “Unsupported get request”, which just means you are not allowed to read that object.

F.e., I have a public post where shared a video post from another page on my timeline, the type is video and status_type is shared_story, but neither user_status nor user_videos allow me to read this post – only when I grant read_stream again, my app can read that post. Same with another public post of type status and status_type mobile_status_update – readable with read_stream, not with any of the user_* permissions.

In short: What you want to achieve is not possible any more with API v2 and the restriction that read_stream will only be granted to apps on platforms where no official FB client exists.

like image 74
CBroe Avatar answered Sep 22 '22 20:09

CBroe