https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension#extendingpagetokens
After reading through this documentation I was under the impression that I could get a token that never expired if I requested a short lived access token with the scope manage_pages however when I follow the documentation and use the following to get an extended token:
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
Then I place the token inside of the debugger: https://developers.facebook.com/tools/debug/accesstoken/
I get the following response:
The closest I've found to what I'm doing is this: How do you get long-lived access tokens from the Facebook Graph API (server-side auth)?
Perhapse is it another scope they requested that I didn't?
Also another thing I noticed is that due to not being a live app these are the "permissions" I have, of which manage_pages isn't one. However how could any new product work if the app needs to exist before it can function????
any and all help appreciated
Go to Facebook Graph API Explorer get your short-lived access token.
Go to Access Token Debugger, debug your short-lived access token from Step1, click the extend button at the bottom, you will get a long-lived token
Go to Facebook Graph API Explorer again, now use your long-lived token from Step2, request path /me/accounts, find the corresponding token for your target page in response data
to make sure it is the never expire token you need, debug it by Access Token Debugger
Ref: https://sujipthapa.co/blog/generating-never-expiring-facebook-page-access-token
Related
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"
I've read that the search endpoint needs a user access token. However it expires quickly, and I'm just doing .ajax() get requests like
https://graph.facebook.com/search?q=new+york&type=event&access_token=USER_ACCESS_TOKEN
without using any SDK, just retrieving JSON data.
I'm hardcoding a new access token every hour, is it another way to do it?
One way of doing it is by using the long-lived User Access Tokens instead of the short-lived ones. You can generate a long-lived User Access Token by using your short-lived user token, your app ID and app secret by making the following call from your server to Facebook's servers:
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-token}
You can find more info about it in the link attached and here.
I am having problems generating long lived Access Token to update Facebook page from my desktop application.
I created a Facebook App associated with my Facebook user and stored it's app id and secret.
I created a facebook page associated with my Facebook user account.
I can create a short lived (60 minutes) access token for my app.
My desktop application is able to post to my Facebook page using the short lived access token. However, this only lasts 60 seconds and is therefore impractical.
I have been trying to generate a long lived access token using the guidance here:
Request a Page Access Token in C# SDK
However I receive an error:
"The access token does not belong to application XXXXXXXXXXXXXXX"
When I try enter my short lived access token in the debug tool the box, it confirms that the access token is mine BUT it shows a different app id.
Where does this different app id come from? I only have one Facebook app defined.
I think I might be missing a fundamental point here.
Many thanks for any help you can give.
Go back to the Graph API Explorer where you generated the token.
Make sure that you selected your app from the drop-down at the top where it says "Application[?]"
If you don't it defaults to 'Graph API Explorer' and that will be of no use to you. Once you get the token made for the correct app, try again using this URL:
(replace NNNN with the correct data)
https://graph.facebook.com/oauth/access_token?client_id=NNNN&client_secret=NNNN&grant_type=fb_exchange_token&fb_exchange_token=NNNN
Steps are:
Generate app token with the following Graph API call:
GET /oauth/access_token?
client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials
Exchange received token for a long-lived token (60 days) with the following Graph API call:
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
that will give you long-lived token associated with your app. If you want to post on the page AS THE PAGE, then you need to get Page access token - see here for more details: https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens
Authenticate the user and request the manage_pages permission
Get the list of pages the user manages from (1): https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Parse the list and get the token - and use it to post to the feed.
you will do (1) in graph API explorer - and you will get user token. Then insert that token into URL in (2) - and you will see all your pages and corresponding token. Take the one you need and use it in your C# code to upload images.
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.
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/