Getting Short-Lived and Long-Lived Access Tokens

Learn how to generate OAuth2 short-lived and long-lived access tokens.

After we have gotten our App ID and App secret, we will generate our access tokens.

Short-lived access token

In the Facebook Graph API, short-lived access tokens are temporary tokens used to access the API on behalf of a user. These tokens have a lifetime of about an hour, after which they expire and can no longer be used to access the API.

We can obtain the short-lived access tokens by redirecting to the Facebook OAuth dialog and getting an authorization code. Afterward, we exchange the authorization code for a short-lived access token by making a server-side request to the Facebook API.

These tokens can access the user's data that the app has permission to access. The apps can use these tokens to make API requests on behalf of the user, such as reading the user's profile information, posting to the user's timeline, and more.

Click the "Run" button in the widget below, click the app URL, and log in to your Facebook account to get a short-lived access token.

Get hands-on with 1200+ tech skills courses.