FQL: Unable to read data from insights table - facebook-fql

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.

Related

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

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.

is it possible to get insights for an OpenGraph object?

I want to get insights for a specific OpenGraph object (such as total impressions, clicks, etc..)
I'm getting the object id for the url by using FQL SELECT id FROM object_url WHERE url=......
Once I have the object id, is it possible to get insights for it ?
I tried with https://graph.facebook.com/objectid/insights without too much success..
according to Facebook's documentation, FQL can be used to get insights for a specific story, but I don't have any story ids..
is it possible to get those insights or do I have to store the action id for each generated action and get insights for those recorded action ids ? (btw - is an action id == story id ?)
btw - I'm doing everything with an app access token.

Facebook API: Can I access my page's user's content?

I'm trying to develop a management tool for my pages and to do that, I need access to the content my users post (as I repost a lot of their content - ex. photos)
It looks like I can get access to all the content that I post, but I can't seem to find any reference to features that'll allow me access to the user's content.
Is this not available in the API?
You can get all the posts for a page at:
https://graph.facebook.com/[PAGE_NAME_OR_ID]/feed?access_token=...
However, you can't filter on this very well. An option that gives you more control is FQL. This query of the stream table should get you started with posts by others.
SELECT post_id, actor_id, message, attachment, permalink FROM stream
WHERE source_id = [PAGE_ID] AND filter_key = 'others'
If a user has set their post to private, it won't be returned by this call. You also need to be aware of the limits of the stream table: It only returns up to 50 posts in the last 30 days. If you want more, you have to use a LIMIT clause to page through your results.
I am developing Facebook application from last two years as per my experience you can't get any users information and using Page Signed request you can get userid,isowner,timezone and isLiked only..

What is the difference between a Facebook Page "Like" and an external URL "Like"? And will the "user_likes" permission scope give access to both?

I'd like to pull a list of all Facebook "Likes" for a user, whether they are Facebook pages or external URLs.
Example:
If you "Like" the Facebook Platform, I know I can see it via the /me/likes API call.
However, if you like an external URL, I'm not sure how to pull that. Are both supposed to be pulled via the /me/likes call? Or is there another call to handle external likes?
Further, what about newsfeed / stream likes? For example, if I "Like" a photo, video, status or link that I see in my stream, is that accessible via the API? If so, how is this accessed?
Yes, user_likes will give you access to both.
You can access external likes as you wish through the Graph API endpoint /me/likes, as long as they're not articles. Objects with type "article" do not represent real-world objects and as such, we don't provide on a person's profile. We mention this (albeit obscurely) on the Open Graph documentation page: https://developers.facebook.com/docs/opengraph/#types
So if you go to my fake movie object page at
http://fbsb.hoodlu.ms/so_7436857/video2.html
and click like, that will show up when you access your likes on https://graph.facebook.com/me/likes.
Try it using the Graph API explorer:
https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Flikes
If you want the URLs that someone has liked, use this FQL query:
SELECT url FROM url_like WHERE user_id = me()
More information is available at https://developers.facebook.com/docs/reference/fql/url_like/.
If you want to access the likes from a post, photo, video, etc. you'll need to use the like and stream FQL tables. To just pull out the likes (of posts/photos/videos) for the current user:
SELECT user_id, object_id, post_id FROM like WHERE user_id=me()
From there, you would query the stream table for the post to get more information.
like table documentation: https://developers.facebook.com/docs/reference/fql/like/.
stream table documentation: https://developers.facebook.com/docs/reference/fql/stream/
Facebook now has two ways to read likes. If you would like to get the likes of an external URL you try this:
http://graph.facebook.com/me/og.likes/[ID_FACEBOOKOBJECT]
And if you wish get the likes from an internal Facebook page (fan page,profile,photo like) try this:
http://graph.facebook.com/me/likes/[ID_FACEBOOKOBJECT]
Checkout: https://developers.facebook.com/tools/explorer

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.