Facebook Access Tokens provide authorization of the app to access specific parts of a user data. Technically, access tokens are opaque strings that are used to make requests to the APIs. These tokens identify a user, app, or Page and can be used by the app to make graph API calls. However, these requests are made by an app instead of a user. Most of the developers require access tokens to integrate it with their programs. They can use these programs to perform various functions like changing the parameters of the app or reading app insights.
In short term
In simple words, when someone connects with the developers app using Facebook Login and approves the request for permissions, the app obtains an access token that provides temporary, secure access to Facebook APIs.
Depending upon different use cases there are different type of access tokens :
User Access Token:
It is required when the app calls an API to read, modify or write a specific person’s Facebook data. These changes are performed by the app and not by the person directly. This type of token is obtained via a login dialog and requires a person to grant the necessary permissions.
App Access Token:
It is needed to modify and read app settings. It is generated using a pre-agreed secret between the app and Facebook and is then used during calls that change app-wide settings.
Page Access Token:
It is similar to user access tokens but differs in the fact that it provides permission to APIs that read, write or modify the data belonging to a Facebook Page. You can get this token by first obtaining the User Access Token and then getting the Page Access Token
via Graph API.
Client Access Token:
This type of token is actually an identifier that can be embedded in native mobile binaries or desktop apps to identify an app. It is not a secret identifier due to the fact that it is embedded in the apps. It is used to access app-level APIs. However, it is applicable in a
very limited subset.
Types of User Access Tokens
User access tokens are of two forms:
- Short-lived tokens: They last for only an hour or two after they are created.
- Long-lived tokens: They usually have a lifetime of 60 days.
You can check the lifetime of the access token you create by going to the “Access token Debugger” page and checking for the time-stamp value. Even if the overall description sounds tricky, getting Facebook user access tokens is really very simple and quick.
Follow the steps below to get yours:
- Step 1: Go to Graph API Explorer using this link- https://developers.facebook.com/tools/explorer/ You will be landed on the Facebook for Developers page.
- Step 2: In Facebook App, select an app used to obtain the access token.
- Step 3: In User or Page, select User Token.
- Step 4: Under Permissions click the check box to accept the terms and conditions.
- Step 5: Click Generate Access Token. Once you do this, the access token will be generated. It is available in the box on the top of the button. You can copy this token and store it for further use. However, the token that you generated now is short-lived i.e. it may expire within an hour or two. If you want to a long-lived token you can continue with further steps.
- Step 6: Go to Access token Debugger using this link- https://developers.facebook.com/tools/debug/accesstoken
- Step 7: Scroll down to the bottom of the page and click on Extend Access Token.
- Step 8: A new access token will be generated which is long-lived. Copy this token and store it for future use.
You can always get more information about your token on the same page, for example App ID,
expiration time and scopes. You can also get the access token manually. For this purpose, you have to click ALLOW when you are prompted for Extended permissions. You will be redirected to a URL that contains the value of the redirect_uri parameter and an authorization code.
Python Code find and get facebook access token
Now you can manually build a URL that includes the endpoint for getting a token, your app ID, your site URL, your app secret, and the authorization code you just received. It may have the following format:
https://graph.facebook.com/<API_VERSION>/oauth/access_token? client_id=<YOUR_APP_ID> &redirect_uri=<YOUR_URL> &client_secret=<YOUR_APP_SECRET> &code=<AUTHORIZATION_CODE>
In this way, you can generate your Facebook User Access Token in just 1-2 minutes using
these very easy steps.
In this article we saw How can find and get facebook access token using python so about this article you have any then free to ask me
Credit: Sanjana Sawant