get insights data of facebook page - facebook

I want to get insights data of a facebook page. I have tried with graph api with this url:
https://graph.facebook.com/149279625121774/insights/?access_token=XXXX
but it gives empty data:
{ "data": [
], "paging": {
"previous": "https://graph.facebook.com/149279625121774/insights/...",
"next": "https://graph.facebook.com/149279625121774/insights/..."
}
}
'149279625121774' is the page id.
Is anybody help me for this.

UPDATED ANSWER:
Insights can be retrieved only as an array. To read Insights you need
a generic access_token for the publicly available application_active_users metric
a generic app access_token for all Insights for that app
read_insights permissions for all apps, pages and domains owned by this user
For more details on which insights are available please review the FQL Insights table
Here are my comments:
Most likely you don't have the read_insights permission.
The user authenticated should be the owner/admin of the page!
Remove the trailing slash /

I found the solution.
You must change the order of the scope parameter:
Try
email,read_insights,manage_pages
Instead of
email,manage_pages,read_insights

Related

How to display "from" fields in comments via Facebook Graph API

I would like to find the id (app-scoped) for someone who has posted a comment on a public page.
For example, I get a list of recent posts/comments on the NY Times page via:
v2.11/nytimes/feed?fields=comments.limit(10){message,created_time,from},name,message,from&limit=2
The data returned looks like this:
"comments": {
"data": [
{
"message": "Wouldn’t know. Not paying $13/mo for this.",
"created_time": "2017-12-10T05:57:18+0000",
"id": "10151412260164999_10151414049324999"
}
],
There is no from field. The same is also true if I attempt to view the comment directly using it's id with
v2.11/10151412260164999_10151414049324999?fields=from,message,created_time
I have tried using the Facebook Graph API Explorer, using both my User Token, as well as an App Token.
Since v2.11 of the Graph API, you need a Page Token to get user data of comments: https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi-90
User information will not be included in GET responses for any objects owned by (on) a Page unless the request is made with a Page access token. This affects all nodes and edges that return data for objects owned by a Page.
In other words: You can only get user information if you manage the Page.
Edit: Since the latests update in the Graph API, you have to get the App reviewed and you must go through Business Verification or Individual Verification. (thanx #Guiman04)
Please check whether you are using the accessToken for the page you are trying to get data from, i had same issue, and was resolved by using the correct accessToken for the page.

How to get results from Facebook Insights API

I'm trying to get useful data from the Insights section using the the Graph API Explorer.
I've tried different metrics and dates, and the results for data is always empty.
I was able to look at my page dashboard for number of likes and select a range based on that, but I still don't see any data.
If the access_key is an issue, would it return an error saying so, or just return empty results?
Here is the debug output from a popular company that I would imagine has new likes in the past few weeks.
=== Query
curl -i -X GET \
"https://graph.facebook.com/v2.8/14226545351/insights/page_positive_feedback_by_type?since=1487788679&until=1490812690&access_token=<access token sanitized>"
=== Access Token Info
{
"perms": [
"user_likes",
"manage_pages",
"pages_show_list",
"public_profile"
],
"page_id": 167544343274096,
"user_id": "10152810337959467",
"app_id": 145634995501895
}
=== Parameters
- Query Parameters
{
"since": "1487788679",
"until": "1490812690"
}
- POST Parameters
{}
=== Response
{
"data": [],
"paging": {
"previous": "https://graph.facebook.com/v2.8/14226545351/insights?access_token=<access token sanitized>&pretty=0&since=1484764668&until=1487788679&metric=page_positive_feedback_by_type",
"next": "https://graph.facebook.com/v2.8/14226545351/insights?access_token=<access token sanitized>&pretty=0&since=1490812690&until=1493836701&metric=page_positive_feedback_by_type"
},
"__debug__": {}
}
=== Debug Information from Graph API Explorer
- https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=14226545351%2Finsights%2Fpage_positive_feedback_by_type%3Fsince%3D1487788679%26until%3D1490812690&version=v2.8
Is anyone able to give an actual working example? I have not come across any yet.
I discovered in the Graph API explorer, when you generate an access token, you need to give it permission "read_insights".
Also, this will only work on a page which your account has access to that given object.
Unfortunately the documentation is pretty vague in this area and there was no permissions error message give.
This might be a bit late, but better late then never I guess :)
On this Facebook docs page you can find a list of all the metrics you can use.
As for empty data, I had the same problem. I could never find how to get data from Facebook Insights; but thanks to the cheatsheet, I can give you an example:
Facebook Insights Example
https://graph.facebook.com/{page_id}?fields=insights.metric(page_fans)&access_token={access_token}
EDIT
Also, user Ravi Patel has a great, working example showing how to get insights from your posts:
/{page-id}/posts?fields=insights.metric(post_impressions_fan,post_engaged_users)
Original question

How to get likes_count with only publish_action permission?

I have a web application that uses Facebook API. Now, I'm facing with an issue on getting the total of likes from a user's post.
I have a long lived "userToken" valid for 2 months with the following scopes: public_profile, email, manage_pages, publish_actions
I use "POST /feed" to send a link into the user's timeline and I get a post ID.
Then, I try to get the total of likes for this post with "GET /{POST_ID}/likes?sumary=true" and I get ZERO likes even if the post has many likes.
{
"data": [
],
"summary": {
"total_count": 0
}
}
I tried to use only "GET /{POST_ID}" to get post information and I get the following json response:
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100
}
}
I have this issue only when I post to a user's timeline. However, when I post to a Facebook page, I can get the post ID and the numer of likes.
I made a test by adding read_stream scope and I can get the post information. However I read in API documentation that this permission has a limited use: "This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available"
Then, I started to check other applications that get post likes and I noticed that they are using only public_profile, email, manage_pages, publish_actions. They are not using read_stream.
So, my question is how they can get this information only with these scopes?
I hope anyone of you will be able to help me?
Thanks
Can you please check, if the post is public.
If you have the post id of a public post you can fetch the likes simply by requesting the endpoint you already mentioned.
To get your feed you need the read_stream or user_posts permission.

Facebook Graph API and Insights not working

I simply want to pull insight data for my company utilizing the Facebook Graph API. I am testing using https://developers.facebook.com/tools/explorer.
When I enter https://graph.facebook.com/MY_ID/insights? and an Access Token I would expect to see JSON data with such data as Page_Views. However I only see this:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/MY_ID/insights?format=json&since=1337268417&until=1337527617",
"next": "https://graph.facebook.com/MY_ID/insights?format=json&since=1337786817&until=1338046017"
}
}
Any suggestions on the URL or perhaps I shouldn't be using Graph API to view Page_Views?
From the Page object documentation, for the insights connection:
Permissions: A valid access_token with read_insights permission for a user
authorized to view the Page's insights
In the explorer click the Get Access Token button, change to the "Extended Permissions" tab and check the "read_insights" box, then click the button and try again.
For anyone else who might run into this issue that wants to view a 'Page' nstead of a user in say v2.4 you might need to use 'Get Page Token' in the 'Get Token' field otherwise you could be seeing what ToddN saw

Can't access news.reads actions using facebook open graph api

I have a facebook account I KNOW has articles posted to the open graph as read actions under the news.reads global namespace (I can see them under the News aggregation in my timeline) but when I try to get a list of them using this api address:
https://graph.facebook.com/me/news.reads?access_token=[my access token]
it returns:
{
"data": [
],
"paging": {
"next": "https://graph.facebook.com/me/news.reads?access_token=[my access token]&offset=25&limit=25"
}
}
as though there were no articles posted at all. I checked my permissions and cant find anything that might be causing this issue. Anyone know how I should be accessing this data correctly? Thanks!
You need the user_actions.news Permission in order to access the user's list of news reads, otherwise the array comes back empty