3

I can get a list of comments and likes just fine using the facebook sdk. But i can't find a way to get a list of all the users that shared a post (i tried fql as well).

This is the code i used to get the likes:

$facebook = new Facebook($config);

$likes = $facebook->api('/THE_POST_ID/likes',
    array('limit'=>9999999999));
Andrei
  • 1,111
  • 2
  • 8
  • 9
  • 1
    You really should provide some code, and the errors that you are getting running it. It gives people at least a chance of fixing it for you. If you just expect someone to post the code to your solution without so much as a hint, you are really taking long odds. – Fluffeh Jul 15 '12 at 12:32
  • I am not getting any errors. I just don't know what request to make. I am using the graph api and there is nothing there about shares. Only abot comments, likes, etc. – Andrei Jul 15 '12 at 12:52

3 Answers3

4

At the time of writing this, Facebook Graph API allows you to get the count of shares of a post. Using your code, it would look like the following (please not that I'm not doing any exception handling here for keeping the example simple):

$facebook = new Facebook($config);

// fetch the post data.
$post = $facebook->api('/THE_POST_ID/');

// fetch the count of shares.
$sharesCount = $post["shares"]["count"];

Using the Graph API Explorer you can easily see that.

Unfortunately, the API does not provide a "shares" connection like it does for "likes" and "comments". See Post - Facebook Graph API Documentation for details.

On the other hand, there is a dirty hack for retrieving the list of users (only friends and people who shared publicly) who shared a specific post. The solution is explained on another thread: List of people who shared on facebook. But, I would never suggest using that solution.

Community
  • 1
  • 1
1

Yes you can get list of all the shares of a facebook post.

by accessing:

https://graph.facebook.com/{POST_ID}/sharedposts?access_token={ACCESS_TOKEN}

See: https://developers.facebook.com/docs/graph-api/reference/v2.5/post

enter image description here

IRvanFauziE
  • 823
  • 11
  • 16
  • It is not possible to show shares of some posts on page, please check https://developers.facebook.com/docs/graph-api/reference/v2.8/object/sharedposts/ – emir Jan 03 '17 at 15:59
0

I know you're looking to get at shares through the post_id, but can you settle for finding shares by page_id instead of post_id?

If you can, then you can use the following FQL to get the data you're looking for.

SELECT via_id, created_time, owner_comment
FROM link
WHERE owner = me()

You can then compare via_id against the posts author (page ID) to determine if this share came from the post author in question.

Unfortunately, there seems to be a bug with the data return where some of the via_ids come back as 0. There is a ticket in with Facebook which, at the time of this post, has been open for three weeks at medium priority. I have no idea if this issue is specific to my app or affects everyone, but that query might get you what you want.