Getting the last date user clicked like on anything on Facebook - facebook

I'm developing an app on facebook and want to get the last date that the user of my app liked anything on Facebook.
It doesn't matter if its a page, post, comment, link or anything else you can like on Facebook.
Is it possible?
Thanks!

Actually, you can. (Probably added since Peter Bailey wrote his answer.)
Each like has a created_time field. The likes connection of a user object in the graph API returns most recently liked objects first. So if you just fetch the most recently liked item and check its creation time, you can get this data.
The API GET call would be:
/me/likes?limit=1
and the result would look like:
{
"data": [
{
"name": "Steve Jobs",
"category": "Business person",
"id": "113529011990795",
"created_time": "2011-09-23T02:22:22+0000"
}
],
}
You can play with this on the Graph API Explorer.

No.
A timestamp or other type of date value is not part of the information retrievable for likes. Not through FQL nor through the Graph API.

Related

How to get Facebook Insights data of photo feed using Graph API?

Insights API works properly for link feed but it doesn't work for photo feed. For photo feed, Insights API returns 0 or empty even though Insights page shows a high reach and engagement rate.
Here is the url pattern of my photo feed:
https://www.facebook.com/[PAGE]/photos/a.xxx.xxx.[PAGE ID]/[POST ID]/
Insights API returns:
{
"id": "[PAGE ID]_[POST ID]/insights/post_story_adds_by_action_type_unique/lifetime",
"name": "post_story_adds_by_action_type_unique",
"period": "lifetime",
"values": [
{
"value": [
]
}
],
"title": "Lifetime Talking About This (Post) by action type",
"description": "Lifetime: The number of unique people who created a story about your Page post by interacting with it. (Unique Users)"
}
I've been struggeling with the same questions... one thing I can tell you is, that you most likely used a wrong id for you photo post.
Please ensure that you ONLY use ID's retrieved by a facebook api. So this is a sample process:
1. Note your page-id
2. Use GRAPH to query <url-to-graph>/<page_id>/feed?access_token=<your_token>
3. From the response, take the photo-post-id you want to analyze
4. Use GRAPH to query <url-to-graph>/<id_from_step_3>/insights/?access_token=<your_token>
5. Check the metrics returned from step 4 and enjoy!
Please keep in mind that there's an undocumented need to add your page_id to any post_id. So every replacement of {post-id} as it is written in the FB api's will be _.
Hope that helps...

Commenting on Facebook Page Ratings (Reviews) via Graph API

Long time lurker first time poster...
We are working with Facebooks API's to integrate into our web application and we are able to pull a Companies Page Rating via the {open_graph_story} parameter in the {page-id}/ratings section, however we cannot find a way to comment/reply to the rating. The documentation states:
"If a person has rated your page and a story has been generated, you can follow up with the person by posting to the story's comment node." (https://developers.facebook.com/docs/graph-api/reference/v2.0/page/ratings)
however when we pull the variables we retrieve no ID to reference for a comment. This is what we receive back from our authenticated account:
"data": [
{ "created_time": "2014-07-16T05:52:50+0000", "reviewer": { "id": "100000237096397", "name": "Romey Salazar" }, "rating": 5, "review_text": "Great job guys!!!!" } ],
Does anyone know how to retrieve the id for the rating itself so we can append a comment via API? Or some other way to reply/comment to a FB Page Rating?
Thanks!
When you have some ratings/review comments on your page and if you want to post comment to individual review comments as the Page Owner, you can follow the steps below.
1) Below request returns the json object of rating and reviews.
https://graph.facebook.com/v2.9/{YOUR_PAGE_ID}/ratings?field=open_graph_story&access_token={YOUR_PAGE_ACCESS_TOKEN}
The response json will contain ID field for each and every rating/review comments.
2) Using the ID, trigger the below request to post a comment on the rating as the Page Owner. You will need Page access token with manage_pages and publish_pages privilege.
https://graph.facebook.com/v2.9/{ID_OF_THE_RATING}/comments?message=Thanks for your rating&access_token={YOUR_PAGE_ACCESS_TOKEN}
These requests can be tested using Facebook Graph API Explorer
You need to request the open_graph_story field with the ratings endpoint. This will return the open_graph_story data which includes an id. You can then post to the comments endpoint of this story.
You have to make http get request on
https://graph.facebook.com/v2.9/{PageID}/ratings?fields=open_graph_story&access_token={PageAccessToken}
to get detailed response.
Make sure the parameter is "fields" not "field"

Facebook Graph Api url comments and shares count doesn't work anymore

I'm using the facebook comment plugin for my blog and until now, the facebook graph api helped me to retrieve the comment count of each post on my website. So, as I said, the posts that I've written like a month ago, I can retrieve the comment count using php and json_decode like this:
$wsurl = 'http://www.example.com/title-of-the-post/';
$wsjson = json_decode(file_get_contents('https://graph.facebook.com/?ids='.$wsurl));
$cmcount = ($wsjson->$wsurl->comments) ? $wsjson->$wsurl->comments : 0;
Usually, it works cause the "comments" line show up. I don't know why, but now, every new post that I create don't have the "comments" and "shares" line. So, here's what I get from https://graph.facebook.com/?ids=http://www.example.com/title-of-the-post/
Older post:
{
"http://www.example.com/title-of-the-post/": {
"id": "http://www.example.com/title-of-the-post/",
"shares": 6,
"comments": 6
}
}
New post:
{
"http://www.example.com/title-of-the-post/": {
"url": "http://www.example.com/title-of-the-post/",
"type": "website",
"title": "Title of the post",
"image": [
{
"url": "http://www.example.com/thumb.png"
}
],
"description": "This is a great post about great things.",
"updated_time": "2012-12-25T17:57:03+0000",
"id": "66666666666666"
}
}
The "comments" line doesn't show up anymore and I have more information now (some information that I don't care). So, what happened? I didn't change my code at all! By the way, my comment box is still working and display all the comments (And my like button display the "shares" count correctly). Can somebody help me?
Looks like a bug to me. FQL Query is an alternative that still works. Here's an example:
select comment_count, share_count, like_count from link_stat where url = "http://techcrunch.com/2011/04/12/facebook-comments-now-on-over-50k-sites-get-more-social-with-latest-upgrade/"
Try the API Explorer here: http://developers.facebook.com/tools/explorer/?fql=select%20comment_count%2C%20share_count%2C%20like_count%20from%20link_stat%20where%20url%20%3D%20%22http%3A%2F%2Ftechcrunch.com%2F2011%2F04%2F12%2Ffacebook-comments-now-on-over-50k-sites-get-more-social-with-latest-upgrade%2F%22
However I would love it if they changed the Graph API to return share counts and comment counts again.
This official Facebook doc (developers.facebook.com/docs/reference/plugins/comments/) still recommends using the Graph API for comment counts, however it does not seem to work with new pages like this one: https://graph.facebook.com/?ids=http://techcrunch.com/2012/12/27/the-last-imac-question-mark/
Facebook deprecated FQL. So, Don't use fql. You can get the number of shares using the following path
http://graph.facebook.com/?id=http://sriraman.in/
For more information, Refer, http://blog.sriraman.in/url-share-count-facebook-twitter/

How to get who and when a user shared a Facebook post

For my Facebook posts my friends share (not likes) I would like get who shared it and when. Using the graph api I can get the like or comment information and the number of times a post has been shared.
What I am looking for is a graph api call or Facebook fql query for shares which returns a result set similar to this:
data": [
{
"id": "user_id_1",
"name": "Username 1",
"created": "some date"
},
{
"id": "user_id_2",
"name": "Username 2",
"created": "some other date"
}
]
I am also looking for the exact thing for long time now. Since Facebook shows the list of users who shared the post, I was expecting that the same will be available in Graph API. But unfortunately nothing such exists till date.
The best workaround I could find for this problem is scraping the Facebook page for the list of users who shared the given post. I haven't yet tried this solution but this should solve the problem for now. The only issue here is, if Facebook changes the HTML structure of that page, the scraper will have to modified.

Facebook ID from URL

Given a facebook url such as http://facebook.com/cnn, is there any way to get the ID of that page short of scraping it?
It is better (and legal) to do this with graph API. Just perform API request to https://graph.facebook.com/cnn and get id from the response.
Here is the response for cnn:
{
"id": "5550296508",
"name": "CNN",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs178.ash2/41813_5550296508_728_s.jpg",
"link": "http://www.facebook.com/cnn",
"category": "Company",
"website": "www.cnn.com\nwww.ireport.com\n",
"username": "cnn",
"company_overview": "TRIVIA FROM THE CNN TOUR...",
"products": "CNN US...",
"likes": 1689936
}
Facebook's own Graph API supports it. From the documentation:
The "ids" query parameter also accepts URLs. This is useful for
finding IDs of URLs in the Open Graph. For example:
https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/
As of Today(28th July 2015), There still exists an easy way to get page(or user's) id.
Browse to facebook page(or user) url. The syntax is https://www.facebook.com/[username or pagename]
Right click to view source and then search for string "pageID": in case of page. The numeric id next to searched string will be id.
In case of user, search for "uid":.
Been working with it today. So, for people who want to know how this works. Use this:
https://graph.facebook.com/<the_fb-address>?access_token=$accessToken
And remember: this is only for pages. Not user pages/friends' timelines etc.
Those will have to approve your Facebook App first before you can read their profiles.