Facebook Post to wall from - facebook-graph-api

I've a facebook application and a group for that application. Is it possible to make the application automatically post on the group. As far as posting is concern, its ok but how to give the application permission to post on the group?
I'm using facebook graph explorer to test this
https://graph.facebook.com/GROUP_ID/feed, method Post and adding a field 'link' with URL 'http://www.google.com' and selecting application as the application i want. I'm getting this error:
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}

The error doesn’t exactly say this, but I’d guess it’s thrown because your not sending a valid access token.
Get a user access token from one of the users that is allowed to post to that group’s wall.

The problem was a permission problem and the permission needed was user_groups,publish_stream

Related

Facebook Messanger. Invalid token

I'm a page admin and trying to debug messanger bot. Recently, I've changed the password and now when I try to reply to myself in messager via API I get an error
{
"error": {
"message": "Error validating access token: The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons.",
"type": "OAuthException",
"code": 190,
"error_subcode": 460
}
}
The thing is I don't have an access token, to begin with, the doc says
To send messages to someone on Messenger, the conversation must be initiated by the user.
It also says
Apps in Development Mode, are restricted to message people that have a role in the app.
I've tried to
Recreate page token
Block/Unblock page and delete conversion
Tried to remove myself from admins, but that's impossible since I'm the only admin
The only option I see left is to remove the app altogether and create a new one, but that doesn't seem like a good solution
This has nothing to do with the fact that the user needs to message your page first, before the bot can respond.
Your bot needs a page token to perform its actions, and according to the error message, the one you have been using, had expired.
So the token you got set in your bot configuration needs to be replaced with a fresh, valid one.

(#100) Tried accessing nonexisting field (messages) on node type (User)

When I try to get the Messages sent to my Facebook Page, which is linked to Messenger chatbot I get the following error:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (messages) on node type (User)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "A5W_BFDXx9GgriZb697u5zv
"
}
}
Here is also an image of the output:
The Access Token is valid for sure. I have tested below:
Note that the Page is neither Business Verified, not Individual verified. I don't know if this plays a role. However, even though the Page Access Token seems correct, I can't run the GET query.
Update - Use Page Access Token
https://developers.facebook.com/docs/graph-api/reference/page/ doesn’t mention the messages edge any more, but how to use it to send messages, is explained as part of the Messenger API documentation:
https://developers.facebook.com/docs/messenger-platform/reference/send-api/
So, /me/messages is the correct endpoint for that, to be used with a page access token. And since sending messages is a “creating” action, it needs to be a POST request.
Be aware though that you can not just arbitrarily send messages whenever and to whomever you want - usually, the user needs to make contact with your page first, so that your bot can then respond to that. The details of the different types of messaging, and their restrictions, are explained unter https://developers.facebook.com/docs/messenger-platform/send-messages

Facebook Graph API, Unable to post as a page due to permission issue

I have a facebook application, not yet submitted to FB for permission review.
The app is intended to allow user to post and reply to other people's post as their own administrated page.
Upon authorization, the application would request the following permission
Publish action
Publish Pages
Manage Pages
I used my own account, with tester role in the app, to granted all requested permission and verified the result in permission is indeed there in my app settings for the application. I have also verified that my account is an administrator of the page I intend to reply as.
It all seems ok until I tried to post a reply to the API using the page token
https://graph.facebook.com/postid/comments
I receive an error:
{
"error": {
"message": "(#200) You do not have sufficient permissions to perform this action",
"type": "OAuthException",
"code": 200
}
}
I can't think of any reason why the permission is missing. I understand that the three permissions need to be approved by Facebook eventually, but to get approval, I'd need to get my app up running for testing first. Is there anything I'm missing here?

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.

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.