How do you get the users on FB who shared a specific link? - facebook

Is there a way to do this?
I've read about /sharedposts but I'm not sure how to get the Object ID of a link. I tried using FQL to get the ID like:
/fql?q=SELECT id, url FROM object_url WHERE url='http://example.com'
OR even the comments_fbid from link_stat
These two returns an ID but when I do
/1234567890/sharedposts
It returns an empty array even though I've already shared the URL a couple of times.
Is this just not possible?
Thanks!

I think the problem could be the privacy settings of the posts:
https://developers.facebook.com/docs/graph-api/reference/v2.0/object/sharedposts#readperms says concerning permissions that
A user access token with read_stream permission, for someone who is able to view the post after privacy settings are taken into account.

Related

FQL: Unable to read data from insights table

I am trying to access our application's insight data with the following request:
https://graph.facebook.com/fql?format=json&access_token=<removed>&q=
SELECT object_id, metric, value FROM insights WHERE metric IN
('application_widget_comments_views',
'application_widget_comments_views_unique',
'application_widget_comments_views_login',
'application_widget_comments_views_login_unique',
'application_widget_comments_views_logout')
AND end_time=end_time_date('2012-08-01')
AND period=period('day')
AND object_id='10151074438279445'
Access token was obtained as an app access token - Does this mean I don't need read_insights permission?
However I always get back an empty data array. To access insights plugin and domain metrics, what should object_id be?
Fetching data from comment, link_stat tables are working just fine.
Any help would be greatly appreciated.
You aren't getting data because the id you are passing is for a url (a Yahoo Finance url). It seems that application_widget_comments_views... only return data when the object_id is the ID for an app.
Looking through the insights table, it does not appear that there are any ways to get insights for a url other than via the url_like table.
If you've got Facebook comments on a url, you'll need to have the id of the app used to publish the comments and be an admin of the app.

How to find a post when all you know is the post_id?

I have a simple app for submitting data and after submission I have a share option.
When a user actually shares something he is redirected by Facebook to a specified URI.
Facebook also provides the post_id by appending it to the URI (like http://my-redirected-URL?post_id=100001175803635_321643121201516).
So, without asking anything from the user, I can tell if he shared information or not, and I have his post_id (but not his user_id or name).
But how can I see what he actually wrote? I have his post_id. Where can I look?
I've tried the open graph but with no luck.
I thought this was an answer: what is the url to a facebook open graph post id?, also no luck.
Any ideas?
If you have user access_token for user who shared the content you can issue GET request to Graph API to get the data by post id (100001175803635_321643121201516 for example):
GET https://graph.facebook.com/POST_ID?access_token=USER_ACCESS_TOKEN
Response is the Post object which will have non empty message property if user added some text to shared content...

List of people who shared on facebook

I've been scouring the docs for a while now and can't seem to find a way to accomplish this. The information is available publicly (on a facebook page ... the link says "View all # shares") but I can't seem to find a way to access this info either via FQL or the graph API.
I know I can get a list of likes for a given post:
https://graph.facebook.com/87236249496_134765166623967/likes
The goal is to get a list of people who've shared -- but there doesn't seem to be the same sort of thing for shares. Am I missing something?
You can do it via "graph.facebook.com/OBJECT_ID/sharedposts" connection:
I figure it out this connection via metadata=1 parameter:
Go to... http://www.facebook.com/ajax/shares/view/?target_fbid=10154612868272801&__a=1
10154612868272801 is Facebook story ID, __a stands for asynchronous.
You will see large amount of text/JSON, it is basically HTML & JS for little popup window. There is portion of text like hovercard.php?id=# where # is Facebook user ID, using preg_match_all you then get all of the user ID's who shared that post.
Eg: 100000541151971 (Eric) and 9204448 (Courtney)...
Unfortunately, you must be logged into Facebook to do first step, figure it out :)
I think you can get the share_count from stream table by FQL query just like
SELECT type, source_id, share_count, permalink, description, post_id, actor_id, target_id, message , share_count
FROM stream
WHERE filter_key = 'others' and post_id = '87236249496_134765166623967'
you can test it https://developers.facebook.com/tools/explorer/
Note: you have to take the read_stream permissions as explained here
Tye this link: https://graph.facebook.com/134765166623967/sharedposts (with a valid access_token)
The id in the link is the wallpost id (87236249496_134765166623967) minus the page id (87236249496) and minus the underscore.
You'll also need the read_stream permission
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.

facebook api access a page's photo album

So really what i would like to do is access my page's photos albums to include them into my own website. So i can upload to facebook and have that viewable on my own site.
I using the php skd but fql would be better for this as i can easily get a JSON object back and i believe i wouldn't need to use the sdk as this is for user's informtaion not a pages details.
So does anybody have ideas on this?
url i'm trying to access the query:
https://api.facebook.com/method/fql.query?query=SELECT%20name%20FROM%20album%20Where%20aid=%27118818791532414%27&format=JSON
Page i am taking the photos from:
www.facebook.com/mayfieldathleticfc
Album i am using as an example:
http://www.facebook.com/media/set/?set=a.118818791532414.24873.118816378199322
I thought maybe i hadn't set the photos to public but after closer inspection i don't believe you can do this?
Anyway thoughts are welcome =)
That URL returns to you an informative error message:
{"error_code":102,"error_msg":"Session key invalid or no longer valid",
"request_args":[{"key":"method","value":"fql.query"},
{"key":"query","value":"SELECT name FROM album Where aid='118818791532414'"},
{"key":"format","value":"JSON"}]}
To call Facebook APIs, you have to pass in a session key - even to access 'public' things. A good starting point for learning how to authenticate and get a session key is http://developers.facebook.com/docs/authentication/
After a little more routing around i realised that it was my id's and owners details that was not correct: api.facebook.com/method/… i had this sorted it worked.

Get Facebook Link Likes

Using the Facebook API with the FQL language, how can I get a list of the users that liked a given URL? I got the URL and want to query Facebook to see how many people and what users liked that URL.
Using PHP or ASP.Net... doesn't matter, just want to know how to write the FQL query.
Sadly this data isn't available. What's possible via the Link Graph API objects and the link FQL table is just retrieving a given instance in which a link was shared by a user. You can get the count of likes on a user's posting of a link, but this likely isn't what you want.
Discussed this 3-6 months ago with guys at Facebook, and the consensus then was also that getting this data via API is impossible. As far as I know things haven't changed, and there are some privacy arguments for keeping this data out of the API.
'SELECT user_id FROM like WHERE object_id IN (SELECT link_id from link WHERE url = 'YOUR URL HERE' AND owner = 'YOUR USER ID HERE' '
Like FQL Table
Link FQL table
In order to access user's likes, the application needs to have user_likes permission from the user. After that if you access http://graph.facebook.com/me/likes with appropriate access tokens, all the object IDs (including external websites), the current user has liked will be listed.
(this is in reply to bounty question, which seems a bit different from the original question asked on this page)
It's not using FQL but...you can see the most recent 500 users that have like your page by going to: https://www.facebook.com/browse/?type=page_fans&page_id={id} but you would have to scrape this to get the information and it won't work for more people besides the most recent 500. Here's the gotcha, you've gotta be an admin of the page_id to see it.
You can only get the fans of pages that you are an administrator for. So you have to provide an access token with your request associated with an admin account of the page you are trying to get the fans.
Facebook's FQL documentation here: https://developers.facebook.com/docs/reference/fql/page/ tells you how to do it. Run the example SELECT name, fan_count FROM page WHERE page_id = 19292868552 and replace the page_id number with your page's id number and it will return the page name and the fan count.