Facebook page: Permission update - facebook

I had an unknown permission exception when I tried to update/create/delete or doing anything my Page properties by using FB.api . I tried again by using Graph API Explore but it still gave me same error. I used google for 2 days but there wasn't any correct answer.
Below screenshot is my app Settings in the Adminster Page's account:
http://demos.kksolution.com/Facebook/screenshot/post-update-about-page.jpg
And here is the Graph API Expore screenshots:
demos.kksolution.com/Facebook/screenshot/list-pages.jpg
Next is the error:
demos.kksolution.com/Facebook/screenshot/post-update-about-page.jpg
Please help me. Thanks too much.

You need a page access token.
Page Access Token – These access tokens are similar to user access
tokens, except that they provide permission to APIs that read, write
or modify the data belonging to a Facebook Page. To obtain a page
access token you need to start by obtaining a user access token and
asking for the manage_pages permission. Once you have the user access
token you then get the page access token via the Graph API.
Doc: https://developers.facebook.com/docs/facebook-login/access-tokens/
Then use GET /me/accounts to get the access token associated to your page.

Related

Programatically determine if access token is a Page Access Token or User Access Token

At the moment, I am trying to download dark posts from the /{user-id}/promotable_posts edge. From the documentation, I can download them using a user token with the ads_management permission or with a page access token.
I am able to check for the permission using the /debug_token node, but I need a way to determine if an access token is a page access token using code/api calls.
Thanks
You can do it by GET https://graph.facebook.com/v2.7/debug_token?input_token={access_token}&access_token={access_token}. If it is a page, response will contains profile_id which is the page id

Get access token from facebook using graph API

I have created the page in facebook and I would like to get facebook stats daily using graph API.
I can get access token by using facebook explorer tools , but it is expired shortly.
I need long live access token to get insights details by using graph API. It would help to get facebook stats daily. If anyone knows it, please share your suggestions.
Thanks in advance!
You will need to gather the access token from your user with permission 'manage_pages'.
Then you can use this request
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
to obtain a long living page access token.
Use this for your statistics.
Read about the tokens here: https://developers.facebook.com/docs/facebook-login/access-tokens
Get the user access token with manage_pages permission
Extend the user access token as explained in here: https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension
Use the above token and get the page access token using /v2.5/{page-id}?fields=access_token
The token you get here wont expire.
Follow facebook docs to get long-lived user access token
curl -i -X GET "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&
client_id=APP-ID&
client_secret=APP-SECRET&
fb_exchange_token=SHORT-LIVED-USER-ACCESS-TOKEN"

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!

Obtaining Facebook Page token via Facebook Graph Explorer?

I am trying to follow the steps on this page but using the Graph Explorer instead: http://aseriesoftubes.com/articles/obtaining-facebook-page-access-tokens-the-4-step-program/
Can someone help with steps in getting a permenant Page Token from the Graph Explorer? Some posts are outdated and referring to offline access. Thanks for any help or advice.
This article is correct, i just tested it: http://www.devils-heaven.com/facebook-access-tokens/
See "Extended Page Access Token" in the article: Basically you have to authorize yourself with the "manage_pages" permission, then you need to extend your User Access Token, and with that Token you make a call to /me/accounts to get the Extended Page Access Tokens for all your pages.
STEPS FOR LASTING PAGE ACCESS TOKEN
1- You have to get page access token for a user by this API:
https://graph.facebook.com/{User-id}/accounts?access_token={access-token}
2- Then u have to refresh the save token by below API which will last for 60 days:
https://graph.facebook.com/oauth/access_token?client_id={your-client-id}&client_secret={client-secret}&grant_type=fb_exchange_token&fb_exchange_token={previous-access-token}

How to get permanent access token in graph API

I created an APP on Facebook and using graph API explorer, I selected my app from app drop down box, requested access token with manage_pages, offline_access and publish_stream permissions.
Using this access token, I was successfully able to post message on page using restfb APIs but when I log out, it starts throwing The session is invalid error.
I read on few posts that offline_access is deprecated. Could someone tell me how to obtain permanent access token?
Thanks
Looking at the docs at: https://developers.facebook.com/roadmap/offline-access-removal/ this is no longer possible.
Desktop applications will not be able to extend the life of an
existing access_token and the user must login to facebook once the
token has expired.
Otherwise, it is possible to request an access token with a longer expiration. Here are the directions: https://developers.facebook.com/roadmap/offline-access-removal/#extend_token
What kind of Access Token do you need? There are three kinds, User AT, App AT and Page AT.
If you want User AT, it seems you are out of luck. I don't think it's possible anymore. You can only get to 60 days. However, if you need Page AT, you can get a permanent one. The difference is, Page Access Token only has access to a single facebook page.
Basically you need to get User Access Token first, with manage_pages permission. When you have one, you have to look at /{pageId}?fields=access_token for your page's id in Graph API.
For more info look at: facebook: permanent Page Access Token?
you will not get any permanent access token as Facebook developer blog explains. you will be given 60 days long lived access token. Before the expiration Facebook will notify you about the expiry and then you can renew it or you can build your own custom control to get the notification on token expiration which you can fetch from Facebook API.