Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook API: Get Shared Post ID

Using FB Graph API, is it possible to check if the post is shared like this one? https://www.facebook.com/alexey.kosov/posts/10203624447732200

And how to get the original post id?

like image 270
Alexey Kosov Avatar asked Oct 09 '15 12:10

Alexey Kosov


People also ask

How do I get my Facebook API user ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.

What data can I get from Facebook API?

With the Facebook Graph API, you can access a wide range of user data, including user information such as name, email address, birthday, and friends list in JSON. You can also access information about pages that a user has liked or engaged with on Facebook, as well as events and photos that they have posted or shared.

How do I share a Facebook post with API?

Yes, you can share using the graph2 api. The way you do it is to use /feed edge and pass the post's url that you want to share as the link. Standard Fb permissions to the post you are sharing do apply. This was done today, in a local rails app, using FbGraph2 gem, with the above method.


1 Answers

In your URL https://www.facebook.com/alexey.kosov/posts/10203624447732200 the 10203624447732200 is your public post id. With the API v2.0 you can get the shared posts with the edge sharedposts: https://developers.facebook.com/docs/graph-api/reference/v2.0/object/sharedposts

According to the documentation on v2.0:

For page posts, public posts by the page are retrievable with any valid access token. Posts by people on the page, posts by people which mention the page, or targeted page posts (by language or geography, for example) may require a user or page token. A user access token with read_stream or user_posts permission for any other posts

So you need a token with one of the two permissions.

I tried to retrieve the share from your post: https://developers.facebook.com/tools/explorer/?method=GET&path=10203624447732200%2Fsharedposts&version=v2.0

And it returned me {"data": []}, however after I shared the post, I repeated the call and I was able to see the post that I just shared in the results.

Now, if I use the post_id that I just shared, I receive again an empty result. So you can see only see who shared the post but not if it was shared from somebody else. If you think of shared posts as nodes of a tree, you can only see what happens on the subtree under the node with the post_id that you have.

You also need to consider that you will not be able to retrieve the re-shared posts that are not visible to you. i.e.: if I share your post with privacy "Only me" or if I share it with privacy "Friends" and we are not friends you will not be able to see it.

like image 99
Chris Cinelli Avatar answered Sep 21 '22 13:09

Chris Cinelli