Getting started with Facebook for developers: Use facebook in a different way

Tech Geek
4 min readAug 14, 2019

--

In this article, we will explore how to get a short-lived user token, exchange with the long-lived user token, get a permanent page access token and make facebook GraphApi call.

Create an account:

To make GraphApi call you need an account. To do this you need to be verified facebook user. Go to facebook for developers page and create an account.

You will be asked to fill in the name of your app.

Get a short-live user token:

You can do this from the graph API explore tool page.

Select your app in the application field.

Click Get Token and select Get User Access Token.

You will be asked to select the permissions associated with the generated token. Select at least manage_page permission.

Note: I selected manage_pages, pages_show_list, publish_pages permissions.

Click Get Access Token when finished.

Congrats! you have a valid Short-Lived User Token. To check its info, click on the blue exclamation mark next to it

Click Open in Access Token Tool, you will be redirected to the Access Token Debugger page

You can see that the Token type is User and that it expires in about an hour and the token has manage_pages, pages_show_list, publish_pages scopes.

Exchange with a Long-Lived Token

Clicking Extend Access Token in the Access Token Debugger should do this.

Congrats! you have a valid Long-Lived User Token. Click Debug to check token info.

You can see that the Token type is User and that it never expires and the token has manage_pages, pages_show_list, publish_pages scopes.

Get Permanent Page Access Token

Copy user long-live access token and paste on graph API explorer.

Select the page for which you want to get the permanent access token.

You will get the id, name and access token of the page in response.

You can select what all fields you want in response.

You can check the token information on Access Token Debugger page.

You can see that the Token type is Page and that it never expires and the token has manage_pages, pages_show_list, publish_pages scopes.

Finally, you can get a Permanent Page Token from the/me/accountsendpoint of the graph object.

Access Token:

  • User Access Token makes calls in your behalf. It’s needed when the app needs to read, modify or write your personal FB data
  • App Access Token makes calls on behalf of the app itself. It’s needed to modify and read the app settings on FB
  • Page Access Token makes calls on behalf of a FB Page. It’s needed to read, write or modify the data belonging to a FB Page you’re managing

Short-Term Tokens and Long-Term Tokens

User access tokens come in two forms: short-lived tokens and long-lived tokens.

  • Short-Lived Tokens: usually have a lifetime of about 1–2 hours
  • Long-Lived Tokens: usually have a lifetime of about 60 days but can also be permanent

Note: Access tokens generated via web login are short-lived tokens, but you can convert them to long-lived tokens by making a server-side API call along with your app secret.

If you enjoy this article, you can give it a ❤ or share it out. Thanks! :)

--

--

Tech Geek
Tech Geek

Written by Tech Geek

I’m a software developer from India, currently working with blockchain.

Responses (1)