How to get the user's information who mentioned a page on Facebook? - facebook-graph-api

I have successfully setup a Facebook App which provides Business Page management.
The goal is to get notified when a Facebook user mentions the said Page and identify who.
Setting up the webhook, for every mention I receive this kind of payload:
{
"entry":[
{
"id":"105569338984024",
"time":1673197963,
"changes":[
{
"value":{
"message":"BusinessPage I mention you",
"post_id":"5882266138421716_3303976449916555",
"created_time":1673137958,
"item":"post",
"verb":"add"
},
"field":"mention"
}
]
}
],
"object":"page"
}
Contrary to messaging or comments, I do not receive any information about the user who created this mention.
How should I get the user info? Or perhaps I did not setup the webhook properly?

Related

Facebook API Instagram webhook not firing

I am having trouble testing Facebook API's Instagram webhooks
Here is what I've done :
My Facebook application is validated with manage_pages, instagram_manage_insights and instagram_basic permissions
My Facebook application is "Live"
I have subscribed my app to my Facebook page POSTing on subscribed_apps endpoint (explained here: https://developers.facebook.com/docs/instagram-api/guides/webhooks/#install-app ). I already use the "feed" field. GETing subscribed_apps endpoint give the following result:
# v6.0/{my-page-id}/subscribed_apps?fields=subscribed_fields
{
"data": [
{
"id": "{my-app-id}",
"subscribed_fields": [
"feed" // the missing "instagram" here seems normal as it is not handled by API
]
}
]
}
Using ngrok I am trying to test the webhook on my local machine. I correctly receive the "test" data (using app dashboard button) but nothing happen when I subscribe to the webhook
I don't understand what I am missing here. The feed webhook I also subscribed too, works perfectly.
UPDATE
I managed to recieve the "story_insights" hooks, so I guess my configuration is OK. But I still don’t get any incoming comment or mention. Are thesi features still available in new graph api versions ?

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.

Access_token for graph api calls in JavaScript

I am trying to pull in and display the wall posts and comments from a public Facebook page on my client's webpage using JavaScript. I know I need an access_token, but the problem is it expires every so often. It seems I would need to dynamically get the access_token to avoid that issue. Does anyone know of a way to do this client-side?
Short answer:
If the page is really public, you don't need an access token at all. For instance,
http://graph.facebook.com/19292868552
{
"id": "19292868552",
"name": "Facebook Platform",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-ash2/276791_19292868552_1958181823_s.jpg",
"link": "http://www.facebook.com/platform",
"likes": 3922010,
"category": "Product/service",
"website": "http://developers.facebook.com",
"username": "platform",
"founded": "2007",
"company_overview": "Facebook Platform enables anyone to build social apps on Facebook and the web.",
"mission": "To make the web more open and social.",
"about": "We're building the social web. Get the latest here: developers.facebook.com ",
"talking_about_count": 74536
}
Longer answer, if you are using a particular user's access token to perform actions on their behalf, you might consider asking for "offline access" so that the token won't expire. See https://developers.facebook.com/docs/reference/api/permissions/ for more information about how to ask for this permission.

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"
}
]
}

Graph API not responding

I am using graph API to get the feed post.
https://graph.facebook.com/128172073865656/feed?limit=200
but it is showing exception
{
"error": {
"type": "OAuthException",
"message": "An access token is required to request this resource."
}
}.
Could any one please help.
Quite simply, you need to obtain and supply an access token with your request.
In particular, the Graph API connections that you're trying to load have been changed recently, and now require an access_token, where they previously did not.
See the Facebook Developer Blog, posts on this:
https://developers.facebook.com/blog/post/509/ - Notification of change in requirements.
https://developers.facebook.com/blog/post/510/ - Confirmation that the changes are now live.