Getting facebook like source information - facebook

Looking at the bottom of this page it would appear that it is possible to get facebook data on where likes are coming from for a particular page. Unfortunately I can't figure out how to do this.
Ideally I would like a method that doesn't use fql something like:
https://graph.facebook.com/PAGE_ID/insights/SOURCE_NAME?access_token=ACCESS_TOKEN
But if that's not possible I would at least think it is possible to do through fql using something like:
https://api.facebook.com/method/fql.query?query=SELECT metric, value FROM insights WHERE object_id=PAGE_ID AND metric='SOURCE_NAME' AND period = period('month')&access_token=ACCESS_TOKEN
but this just returns the xml with the error message Invalid metric name: SOURCE_NAME for whatever source name I'm trying to use.
What is the proper way to access this data? Or is facebook just trying to tease me?

The query I was looking for was something like
https://api.facebook.com/method/fql.query?query=SELECT metric, value FROM insights WHERE object_id=OBJECT_ID AND metric='page_fans_by_like_source' AND end_time=end_time_date('YYYY-MM-DD') AND period=period('month')&access_token=ACCESS_TOKEN

You can try this graph API as below:
https://graph.facebook.com/[page_id]/insights/page_fans_by_like_source/?access_token=?[access]&since=[time_stamp]&until=[time_stamp]

Related

Facebook Applinks return no applink data at all

I'm using the Facebook Graph API, Mobile hosting API to post a link with the following:
https://graph.facebook.com/{APPID}/app_link_hosts?access_token={ACCESS_TOKEN}&name=Puzzle_1420352145684&ios=[{"url":"MyAPP://playerPuzzles/1420352145684","app_store_id":{MYAPPID},"app_name":"MyAPP"}]&web={"should_fallback":false}
I get the correct result in the form of the ID of the link, with no error.
But when I query the link with
https://graph.facebook.com?ids={LINK}&access_token={ACCESS_TOKEN};
I don't get any app-link data the object is there but empty not even the name.
{"http://fb.me/777314042342441" = {
id = "http://fb.me/777314042342441";
};
}
Is there something wrong in my posting that doesn't allow the data to get posted?
Thanks for you help in advance.
It seems that the facebook documenatation is wrong. I finally found a solution using the graph explorer.
To correctly fetch the data use this style of URL.
https://graph.facebook.com/{APP-LINK-ID}?fields=ios,name,web&access_token={ACCESS_TOKEN};
Please note that you have to call out all the fields you want. The object at least for me didn't include the app_links structure like the documentation.
Here is the link to the wrong Index API
Here is the app_links object structure you can see all the fields you can fetch.
Hope this helps everyone.

How to get facebook share, like, comment count for a url with graph api only (in a non-deprecated way)

The problem is that after v2.1 of graph api fql will be deprecated.
Can someone tell me how to get separate likes, share count for given url using only graph api? I was looking for some documentation, but there isn't any, i can get only total "shares" which is likes + shares + comments.
Yes i know there is immortal http://api.facebook.com/restserver.php?method=links.getStats&urls, but what if facebook shuts it down at last?
The REST API (with calls like http://api.facebook.com/restserver.php?method=links.getStats&urls) was announced as deprecated with the introduction of the Graph API v2.1: https://developers.facebook.com/docs/apps/changelog#v2_1_deprecations but also already in 2011: https://developers.facebook.com/blog/post/616/
So, from my understanding, this will yield in the inoperability of this feature at two years after the introduction of v2.1 on 7th August 2016:
https://developers.facebook.com/docs/apps/versions#howlong
The closest you can get to the "old" REST of FQL API call results with the Graph API is this afaik:
https://developers.facebook.com/docs/graph-api/reference/v2.3/url/
but it omits the like_count metric (don't ask me why...).
My personal opinion is that you should continue to use the FQL calls to the link_stat (https://developers.facebook.com/docs/reference/fql/link_stat/) table, because this will be available for nearly the next 2 years. This is only possible if you have a v2.0 app. Maybe there'll be some additional endpoints for the Graph API until then.
I suggest using a tool like SharedCount, it offers a lot more platforms too. Here is how they get the data: http://www.sharedcount.com/documentation.php (Scroll down to "Sources")
So for Facebook it would be like this:
https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
You get a JSON object like this one:
..."share_count":66,"like_count":15,"comment_count":1,"total_count":82...
Edit: This is deprecated now, but there is another possibility, explained in this thread: Get FB likes, shares and comments for a URL using PHP - with no limit
You can use facebook graph api like https://graph.facebook.com/?ids=http://mycodingtricks.com and it will return a json code like
{
"http://mycodingtricks.com":{
"id":"http://mycodingtricks.com",
"shares":1
}
}
I have developed my own php script on which you can all social count using that api.
http://mycodingtricks.com/share/social.php?url=YOUR-URL-HERE and it will return data like:
{
"facebook":[
{
"share_count":1,
"like_count":0,
"comment_count":0,
"total_count":1,
"click_count":0,
"comments_fbid":567687199998199,
"commentsbox_count":0
}
],
"googleplus":10,
"twitter":3,
"buffer":0,
"pinterest":0,
"stumblupon":1,
"reddit":"<html><body><h1>403 Forbidden<\/h1>\nRequest forbidden by administrative rules.\n<\/body><\/html>\n",
"linkedin":0
}
But if you wants to use on your own Here is a complete article about how to count facebook share,like and all.
http://mycodingtricks.com/php/2-ways-to-count-facebook-likes-shares-and-comments-using-php/
actually the correct way for getting the like number is this:
http://graph.facebook.com/v2.5/?id=YOUR_URL&fields=og_object{engagement}
the brackets after the og_object is the second level of og_object.
see documentation here:
https://developers.facebook.com/docs/graph-api/reference/url
you might need to encode the url and brackets so it will look something like:
https://graph.facebook.com/v2.5/?id=ENCODED_URL&fields=og_object%7Bengagement%7D&id=http%3A%2F%2Fwww.cnn.com
see a working example in
graph explorer (hit the submit button)
All answers are wrong or incomplete since latest shut down of API 2.1!
I am the author of the social media plugin MashShare and i recently had to do exact observations for this issue as it seriously affected the share count of our plugin.
Verified data by observations:
https://graph.facebook.com/v2.7/?id=https://www.mashshare.net contains shares and likes.
As far as i found out the only way to get a number near the real share count of a post is to get first the likes of a url. Than take this number and subtract it from the total number of shares and likes.
To get the like count you need to take the object id of the url and create another API request:
https://graph.facebook.com/v2.7/14206851986099/likes?summary=true
If you know how to merge both requests into one please let me know.
As of August 19th 2016 facebook completely shutdown their rest API.
The only alternative is to use the graph API as suggested above.

Facebook graph API: Filter status from feed

I use
http://graph.facebook.com/cocacola/feed?access_token=MY_APP_TOKEN
This works but I would like to exclude the status updates from the result and only get links,photos and videos. There seems to be a filter function as listed here: https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed
But I don't get how to use it :-(
...cocacola is just an example of course...
I also couldn't get it to work with the Graph API itself, because the docs lack (again) details on how to use it.
You can use FQL to achieve what you desire instead:
select post_id, message, attachment from stream where source_id=me() and type in (80,128,247) limit 50
This will return your 50 most recently posted links, videos and photos. Remember that you'll need read_stream permissions if you access user info. For public page posts, this should be fine without.
Try it: https://developers.facebook.com/tools/explorer?fql=select%20post_id%2C%20message%2C%20attachment%20from%20stream%20where%20source_id%3Dme()%20and%20type%20in%20(80%2C128%2C247)%20limit%2050%0A%0A
To change the subject of the query, change the source_id object_id. For CocaCola, this would be 40796308305 (https://developers.facebook.com/tools/explorer?method=GET&path=cocacola%3Ffields%3Did&version=v2.0).

Having trouble with Facebook FQL - Empty Return

I'm attempting to make a Facebook app that will query insights metrics from pages that I administer. I'm unsure if there is a better approach, but I am running into issue after issue trying to build my queries.
For instance, many of the "metric" fields listed here return empty data objects. Testing the following FQL query on the Graph API Explorer is an example (substitute with your page ID):
fql?q=SELECT metric, value FROM insights WHERE object_id=<USER_ID> AND metric='post_storytellers' AND period=0
I have granted myself "read_insights" permissions.
I'm wondering if this is a common issue, if I'm doing this wrong, and if there is a better way (i.e. FQL is problematic, stick to the Graph API). I started this project using Perl, intending to simply parse the return data into a database. Perhaps I would be better served writing this in PHP?
The post_storytellers metric, has only 3 available periods: day, week and days_28. When you put period=0, you are asking for the lifetime period.
Your query should be something like this:
SELECT metric, value FROM insights WHERE object_id=<PAGE_ID> AND metric='page_storytellers' AND end_time=1334905200 AND period=period('week')
I hope it would help!

Issue when trying to requery on postID using facebook graph

Forgive me I'm new to the Facebook graph concept. I've read through the documentation and am a little lost on something that I want to try and do. I have been able to query posts based on a keyword such as "sailing" like so:
http://graph.facebook.com/search?q=sailing&type=post
I see that it returns a result set containing 25 of the most recent posts with the keyword provided. My issue comes when I try to take a post id and query it directly. What I want to do is to be able to take a post id and query it after a 24hr time frame to see if it has received any comments and to see how many likes it has gained since being posted.
I can take the userID_postID and query like:
http://www.facebook.com/userID/posts/postID
I can see the post with the likes but when I try this in the graph:
http://graph.facebook.com/userID/posts/postID
I get the following error message:
{
"error":
{
"message": "Unknown path components: / postID",
"type": "OAuthException",
"code": 2500
}
}
I've seen where people have commented that if you want to access a post you will need to get an access_token. I'm not sure why you need an access_token to access a post that you originally obtained without one. It doesn't seem to make sense. One thing that I have noticed when trying to do this with different posts is that this seems to be related to accessing posts of an individual rather than a fan page. Whereas a public page such as a fan page seems to return the results.
I also tried querying like:
http://graph.facebook.com/userID_postID/likes
this returns the likes for a public page such as a fan page but doesn't return anything for an individual page. Can anyone help point me in the right direction or maybe give me some explanation on what the proper way to handle this would be? Requesting an access_token from the user is something I do not want to do, this is mainly for a service that we're trying to create that allows us to survey based on a keyword. Any help would be much appreciated, thanks.