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

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...

Related

Get All Posts from Facebook Page

I am looking for the information posted on the facebook page. I am able to hit the api as below https://graph.facebook.com/v2.8/203511053776284/feed?limit=100&access_token=XXXXXXXXXXX&format=json. I am able to get the below data but no images related with post.
data": [
{
"message": "This is my first post",
"created_time": "2018-05-16T08:05:02+0000",
"id": "203511053776284_203511440442912"
}
]
Any way to get all the information from facebook page.
You need to pass fields value to fetch additional data.
https://graph.facebook.com/v2.8/203511053776284/feed?fields=id,name,message,story,created_time,link,description,caption,attachments{media,type,subattachments}&limit=100&access_token=XXXXXXXXXXX&format=json.
I recommend exploring Graph API Explorer tool.

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"

Displaying Different Copy / Images Based on the Number of Likes

We're working on developing a program that will (hopefully) automatically swap out creative with new creative once a certain like threshold is met (i.e. if 100 people like the page, something new appears). Can we add coding so our system is able to tell how many "likes" are generated? I know that the number of likes are displayed, I'm just not sure if there is a way for a program to actually read how many likes there are.
I don't see if in any of the Facebook attributes in the developer's platform.
What you'll have to do is acquire an access token for your page and then query the facebook platform for the number of likes periodically (possibly with a cron job of sorts).
You can read more about how to get the page access token at this URL
https://developers.facebook.com/docs/authentication/
Facebook has given us a great took to help us mine all the data it holds - its called the Graph API Explorer and with it you can see what data will be returned when you query the API. When you query the API with only the page_id you'll get a response similar to this :
{
"id": "XXXXXXXXX",
"name": "My Awesome Page",
"picture": "foo.jpg",
"link": "https://www.facebook.com/pages/XXXXXXXX",
"likes": 345,
"category": "Product/service",
"website": "XXXXXXX",
"founded": "2011",
"description": "...",
}
For more information about how to use the Graph API you can see this link :
https://developers.facebook.com/docs/reference/api/
Facebook does provide good documentation:
http://developers.facebook.com/docs/reference/api/page/
As you can see there, there is a field "likes" containing the number (count) of likes for a page.

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.

Getting the last date user clicked like on anything on 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.