Facebook graph api not getting post reach - facebook-graph-api

I am using FB Graph API to get the post reach posted on a page. But the API always returns an empty data object (no errors).
Query:
https://graph.facebook.com/v2.10/[POST_ID]/insights?metric=post_impressions_unique&access_token=[PAGE_ACCESS_TOKEN]
Response:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/v2.11/[POST_ID]/insights?access_token=[PAGE_ACCESS_TOKEN]&metric=post_impressions_unique&since=1528268400&until=1528441200",
"next": "https://graph.facebook.com/v2.11/[POST_ID]/insights?access_token=[PAGE_ACCESS_TOKEN]&metric=post_impressions_unique&since=1528614000&until=1528786800"
}
}
I have tried it with other API versions v2.11, v2.12 and v3.0 etc. same response. And posts do have a reach metric when checked on the page.
Anyone have any clue about whats wrong here?

Thanks to CBroe 's comment pointed me in the right direction.
My app that I used to get page access token didn't have the read_insights permission.
From Graph api Explorer , from the dropdown "Graph API Explorer" in the top right, I selected my app.
From "Get token" dropdown just below it, select "Get App Token".
From the popup window make sure you have the read_insights permission ticked along with others.

Related

Post to Facebook page with Open Graph

trying to figure out why I cannot post to Facebook Page (not profile) with Open Graph API.
I have submitted for review and got approved an action. I have permissions approved, such as:
manage_pages
publish_actions
publish_pages
When I make a post to facebook profile eveything is working fine:
https://graph.facebook.com/me/com-domain:post?access_token={access_token}&method=POST&property={url}&message=test&fb:explicitly_shared=true
The problem appears to be posting to Facebook Page.
First of all I am making request to /me/accounts and getting proper PAGE ID and Page access token.
https://graph.facebook.com/me/accounts?access_token={access_token}
After that, grabing new access token and page id making another request to
https://graph.facebook.com/{PAGE_ID}/com-domain:post?access_token={page_access_token}&method=POST&property={url}&message=test&fb:explicitly_shared=true
And getting result:
{ "error": {
"message": "Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "Ffdsfds" }}
Any suggestions ? Thank you!
After talking to Facebook support it appears that it is not possible to post via custom actions to Facebook Page. Only to profile. Case closed

Accessing users friends work history using GRAPH API 2.3

How can I get the users friends work history? Currently I tried this in the Graph api explorer:
GET /me/taggable_friends?fields=id,name,work&acess_token...
and the query returns the friends, but don't show any job.
The response returns me somethin like this:
"data": [
{
"id": "<some-long-string>",
"name": "<name>"
},
I tried to do this:
GET /<the-some-long-string>...
And the response says me that the user id is incorrect. Googling I didn't found anything :'(
Thank you!!!
From Facebook Developers:
"message": "(#10) To use taggable_friends on behalf of people who are
not admins, developers and testers of your app, your use of this
endpoint must be reviewed and approved by Facebook. To submit this
feature for review please read our documentation on reviewable
features: https://developers.facebook.com/docs/apps/review"

why does posting to facebook page yield "user hasn't authorized the application"

I have read the fb docs and written code to publish a message to a facebook "page", however I am getting an error that I don't expect to see:
(#200) The user hasn't authorized the application to perform this action
Here's what I've done:
I set up a facebook application, which provides my APP_ID and
APP_SECRET.
I set up a test facebook "page". Let us refer to its fb id as PAGE_ID.
Used OAuth to get a USER_ACCESS_TOKEN with scope "publish_actions,manage_pages" for the user. I accepted the permissions requested by my app when redirected to the facebook auth page.
I did a GET on https://graph.facebook.com/me/accounts using the USER_ACCESS_TOKEN, and I get back a list of pages I administrate, including the one I want to post to.
This block of data for my page looks like:
{
"data": [
{
"category": "Community",
"name": "My Generic Test Page",
"access_token": PAGE_ACCESS_TOKEN,
"id": PAGE_ID,
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
},
....
]
}
Then I use the PAGE_ACCESS_TOKEN to post a message to the page:
I did a POST on https://graph.facebook.com/PAGE_ID/feed with a field message equal to This is a test post.
Facebook returns:
{
"error": {
"message": "(#200) The user hasn't authorized the application to perform this action",
"type": "OAuthException",
"code": 200
}
}
Using the token debugger, I can confirm that my PAGE_ACCESS_TOKEN is valid, and has scopes: manage_pages and publish_actions.
Where am I missing authorizing the application? Do I need additional scopes? Did I miss clicking something on the facebook authorization screen? Is there a setting on the app I am missing? After days of debugging this, I must be blind to the problem. :-|
You should add permission called status_update, for example
https://www.facebook.com/dialog/permissions.request?_path=permissions.request&app_id=145634995501895&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html%3Fdisplay%3Dpage&response_type=token&fbconnect=1&perms=status_update&from_login=1&m_sess=1&rcount=1
and i'm able post to page i liked with the access token i get just now:
If you want to post as the admin of the page, you're require both manage_pages and status_update permissions, for example
https://www.facebook.com/dialog/permissions.request?_path=permissions.request&app_id=145634995501895&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html%3Fdisplay%3Dpage&response_type=token&fbconnect=1&perms=manage_pages%2Cstatus_update&from_login=1&m_sess=1&rcount=1
Cheers
status_update is not used anymore. To publish on pages, I had to use both manage_pages and publish_pages.
Well, this seems to be a common mistake that most of us make while trying to do an activity in social netwroks. Before trying to put up an open graph action,You need to set the permissions in your initial authorization request . By default you only gain 'read-only' access to their basic information.
Settintg up permisson at teh time of authetication is a must for Facebook and LinkedIn APIs..
See the public_actions section in Facebook open graph permissions here and make relevant changes in the authorization code , and get your issue solved.
I found the best way to get a valid token and check permissions was via the Graph API Explorer BUT while Facebook's documentation is extensive it is not always the easiest to follow.
In the explorer you have to look at both:
The Application Currently at the top and quite subtle, I missed this for ages.
Get Token Dropdown What you click to get a Token, when you click the arrow you can choose pages and other items you have access to for selecting a token for.

like photo from graph api explorer

I am trying to like a friends photo for some preliminary research on a website feature and I'm finding strangeness in the graph api explorer. I have the publish stream option checked. But when I set the dropdown to POST and set the URL to IMAGE_ID/likes, it reports:
{
"error": {
"message": "Trying Too Often: You are attempting this too often. Please try again later.",
"type": "OAuthException",
"code": 368
}
}
and then I am immediately logged out of facebook. Would a kind soul be willing to try to like a friend's photo through the Graph API explorer and see if it works?
Sure, pass the URL and I'll see what happens.
Tested it with a pic from a friend of mine, worked like charm...

Getting notifications of managed page using Graph API

Is there any way to get notifications of a managed page just as it can be done for users?
For a user I'd trivially trigger a GET request to /me/notifications. I've tried doing the same for a managed page (using the access token provided by /me/accounts), that is triggering a GET to //notifications?access_token= but I get a "Unsupported get request" error message, which I guess means that the notifications connection is not available for pages.
Is there any way to get this via Graph? The web page has a notifications link/shortcut for each managed page.
Per the graph API Explorer, here are the connections you can access of the page, and unfortunately notifications is not currently on their list:
albums
events
feed
links
notes
photos
posts
questions
statuses
tagged
videos
However, you could try fql?q=
SELECT notification_id, sender_id, title_html, body_html, href
FROM notification
WHERE recipient_id=me()
EDIT
I used a valid PAGE access token and was able to get back data....
{
"data": [
{
"notification_id": "nnnnnnnnnnnn",
"sender_id": nnnnnnnnn,
"title_html": "xxxxxxx posted on Beer's timeline.",
"body_html": "",
"href": "http://www.facebook.com/permalink.php?story_fbid=nnnnnnn&id=nnnnnnnn"
}
]
}