Post on page with impersonate access_token? - facebook

I have a question, I'm trying to post on a page with the token acquired from
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
grant_type=client_credentials
I guess the app has permission to post on that page, but when I try to post I get the following error
{
"error": {
"message": "(#200) The user hasn't authorized the application to perform this action",
"type": "OAuthException"
}
}
How do I verify the permission?
Basically, I want to be able to post to a page as a page without asking user to login, Would be great if someone can help me out!

The token that you are acquiring is an App Access Token.
And to post on a page as a page itself, you need a page access token.
To get the page access token, you need to make the following API call with an access token with manage_pages permission:
/{page-id}?fields=access_token
this will give you the page access token for your pages. Use that and publish the post.
You can also have a never-expiring page access token. To get one follow this: What are the Steps to getting a Long Lasting Token For Posting To a Facebook Fan Page from a Server

Related

Figure out which pages I got permissions for from the Facebook Login popup

I'm building a Chatbot and im trying to connect it with the client Facebook Fanpage programmatically, so I can you receive and send messages on the user behalf on the Fanpage.
So far all is good, I got the Facebook login to work, requesting access to the right permissions, and getting the user short and long lived access token.
However, I'm not sure this access token is valid for which Fanpages, The Facebook login lists all the user Fanpages and he can select which he will give the permission to per the screenshot, but nothing is returned in the payload saying which pages he selected, only the access token as below:
"authResponse": {
"accessToken": "EAAJ911mLyc4BAPsNTMCfVqcf5JkvnGsaZCxXZAZA6slQuubSaZANMB3jsUBZB5ds7opfAuV1ZBB5Vz3NZBLwiN3QO1C5NupvGAbIdzxz91JYWHZCJfwOgawzOswgxAevLDmd6yjRQ4LASROcbnyTtHcnBeE08qvWSYJ6sJrzZCptZB94NZA1tz6tVKOIZCIgrhdaM1IB4feF2LCaF86eIXH1yAZCE",
"userID": "2917511921114302",
"expiresIn": 5498,
"signedRequest": "YpjihSoIBgcl2fUxkVBE2b7_mtXD7RK7ZT7sn77uqRY.eyJ1c2VyX2lkIjoiMjkxNzUxODkyMTcxNDMwMiIsImNvZGUiOiJBUUFhNGVZRlJTUnIyNDkwT252dFdEYTlfTnh3cm1QWnNoTUF4bzNUYzdERS00MmZXT0pvTEY4XzUybUJ6VmhzeF81eG05VjFNZV33daVhvM3lQV1FscTE1czZoM25uYUpnTzdObGpxUkJhQTNpRnhtMTA1TFMtbVRPa0dTNGNiNEFpbXN3dTcxcEZiX0hjZG1MVXFldmo5QkVQMXJzYnRkYkw5LWNzSXZlWWIyWmZQR25TNW93aUdCTjRIZmRqdjRSbm9aMkllRDRPN3R1RUtfbmhDMG55cDd1UDZGR1JCOVFaV3ZQQUVEQTNwN2dJX0x3X1ZDYUsteG00Tk9BbkJhZEdnVS16eXJNR3J1S0owZWFLUFF6YkFkNWJRaUJzNmw1a2xvUl9IOFhieFpiMjlaUmJHTjBOUjJoZmk4bHNISU5yMW91SjUyXzJqWTNaTy1xZ3FSX1RObSIsImFsZ29yaXRobSI6IkhNQUMtU0hBMjU2IiwiaXNzdWVkX2F0IjoxNjc1OTUyOTAyfQ",
"graphDomain": "facebook",
"data_access_expiration_time": 1683728902
},
"status": "connected"
}
And screenshots for the page selection from the Facebook login:
How can I can get the pages id selected, so I can request later the page access token for those specific pages? Thanks.

Post on Facebook Page Using FB Graph API using FB Live but un-reviewed App

I want to post on my own Facebook Page using Graph API.
For this, I have created an App.
When App is in Dev Mode, I am able to post on page using Page Access Token with proper permissions.
However, the problem here is, the post are not visible to public unless I make the App Live. The posts are only visible to Page Admins.
But as I make my App Live, I am getting below exception from FB APIs.
{
"error": {
"message": "(#200) If posting to a group, requires app being installed in the group, and \\\n either publish_to_groups permission with user token, or both pages_read_engagement \\\n and pages_manage_posts permission with page token; If posting to a page, \\\n requires both pages_read_engagement and pages_manage_posts as an admin with \\\n sufficient administrative permission",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "abcdefgh"
}
}
I regenerated the Page Access token after I make my App Live but still above error is coming.
I checked some resources which says that I need to submit my App for review. But I don't want to go through that lengthy process.
So, Is there any otherway with which I can post on facebook page using API without putting my App for review process ? Will any other kind of token (i.e. other than page access token) work here ?
Please note, I want to make sure the posts I make to be visible by everyone and not just page admins.

Facebook App Admin cannot post Live Video API request on its own page

I'm using the Facebook Live Video API for testing purpose.
I've created a Test User, associated with my Facebook App, with the following permissions: publish_actions, user_videos, publish_pages, manage_pages
Using graph API explorer, I can make a POST request on /{user_id}/live_videos, using the Test User ID and Access Token (got it from the My App -> Role -> Test Users).
But, if I create a page with the Test User (logged in with its email), POST resquest on /{page_id}/live_videos, with the test user page ID and Page Access Token with required permissions, I get an error:
"message": "(#100) No permission to perform current operation.",
"type": "OAuthException",
"code": 100,
I have the exact same issue when I'm not using a Test User, i.e. when I try to post live videos on a page id with an admin page token, while it works on its user id with user access token.
I've followed these documentation:
Live Video API
Why can't I POST live_videos on page ID with a page access token while it works on user ID with user access token?
Best regards.
Nico
POSTing a live_video with the page access token should work now. After chatting with the engineers at FB, they fixed the problem, so it wasn't an issue with just you.

Facebook Page Access Token can be used to post stuff?

I have read some introduction about Facebook's access token on http://www.devils-heaven.com/facebook-access-tokens/
What I want to ask is that can the page access token of Facebook be used as a permanent token if I just want to post something on the wall like user access token?
First of all don't ever follow the third-party documentation for the facebook integration. They have the official documentation pls follow that. For access tokens read here.
What I want to ask is that can the page access token of Facebook be used as a permanent token if I just want to post something on the wall like user access token?
Its actually a vague question. It depends on what kind of posting you want to do. For eg:
If you want to post on a user's wall- there's nothing that a page access token can do
If you want to post a user's group/event etc. wall, again page access token has nothing to do with it.
If you want to post on a page, then yes you have to use the page access token in order to post on behalf of page itself.
Page access tokens are used in Graph API calls to manage Facebook Pages. To generate a page access token, an admin of the page must grant an extended permission called manage_pages. Once this permission has been granted, you can retrieve the page access token using the following Graph API request:
GET /{user-id}/accounts
You can also extend a page access token that will never expire. See here how to do that!

Extending Facebook Page Access Token

i need to extend my facebook access token, I'm calling this:
https://graph.facebook.com/oauth/access_token?
client_id={MY PAGE ID}&
client_secret={THE SECRET KEY OF MY APP}&
grant_type=fb_exchange_token&
fb_exchange_token={AN ACCESS TOKEN FOR MY PAGE}
and I'm getting this error:
"error": {
"message": "Error validating application. Cannot get application info due to a system error.",
"type": "OAuthException",
"code": 101
}
I've seen a lot of problem with that access_token, but none answer relative to pages, idk why facebook use api that why... but is the way...
Thank you,
To get a long-lived access token you need to follow those steps:
Create an Application
Create a Page (your account need to be "administrator" of the page)
Associate the application to the Page (the same way you do it when you want to add a Page Tab to a Page)
http://facebook.com/add.php?api_key=*YOUR_APP_ID*&pages=1&page=*YOUR_PAGE_ID*
Get a short-lived access token with the permission "manage_pages" associated to your Application.
https://graph.facebook.com/oauth/authorize?client_id=__APP_ID__&scope=manage_pages&redirect_uri=http://www.facebook.com/connect/login_success.html
then
https://graph.facebook.com/oauth/access_token?client_id=__APP_ID__&redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret=__APP_SECRET__&code=__CODE_FROM_PREVIOUS_REQUEST__
Using the Graph API Explorer with the request /me/accounts you can see the access tokens for each Pages that you are administrator. The problem is that those access token are short-lived.
Convert your short-lived access token to a long-lived (extending access token):
https://graph.facebook.com/oauth/access_token?client_id=_APP_ID_&client_secret=_APP_SECRET_&grant_type=fb_exchange_token&fb_exchange_token=_ACCESS_TOKEN_ON_STEP_4_
You can now test your new access token with the Access Token Debugger.
Scenario 5: Page Access Tokens
When a user grants an app the manage_pages permission, the app is able
to obtain page access tokens for pages that the user administers by
querying the [User ID]/accounts Graph API endpoint. With the migration
enabled, when using a short-lived user access token to query this
endpoint, the page access tokens obtained are short-lived as well.
Exchange the short-lived user access token for a long-lived access
token using the endpoint and steps explained earlier. By using a
long-lived user access token, querying the [User ID]/accounts endpoint
will now provide page access tokens that do not expire for pages that
a user manages. This will also apply when querying with a non-expiring
user access token obtained through the deprecated offline_access
permission.
https://developers.facebook.com/roadmap/offline-access-removal/