GNU/Linux, Open Source, Cloud Computing, DevOps and more...

How to get a permanent token to access a Facebook page

No comments

Through the following instructions you can easily get a permanent access_token to automatically connect your applications to a Facebook page and be able to obtain for example your number of followers periodically, get new likes or comments in real time, publish new entries in the timeline, or any of the possibilities offered by the Facebook Pages API.

 

1. Get Facebook page identifier

Método de obtención del identificador de una página de Facebook - Paso 1Método de obtención del identificador de una página de Facebook - Paso 2

2. Create a FB App for your page

2.1 Go to My apps.

2.2 Create new app, for example AppMipagina:

Pasos para la creación de una nueva FB App2.3 The previous step will take you to the administration page of your new App. There you will select the Configuration menu option and the data that we are interested in will be shown: the application identifier and its secret key, which you can only access by clicking on the Show button (#2 in the next screenshot). Do not forget to select the category “Applications for pages” (#3) and save changes:

Página de administración de app Facebook3. Get short-lived access token

3.1 Go to Facebook API Graph Explorer.

3.2 Select the page for which you want to obtain the access token in the right-hand drop-down box, click on the Send button and copy the resulting access_token, which will be a short-lived token (2 hours).

Explorador de la API Graph Facebook para desarrolladores4. Get long-lived access token

4.1 Enter the following URL in your browser’s address bar:

https://graph.facebook.com/v2.8/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={short_lived_token}

That in our example would look like this:

https://graph.facebook.com/v2.8/oauth/access_token?grant_type=fb_exchange_token&client_id=246766729135031&client_secret=7dc9596d6f58cf94bc9e3f6b48decc69&fb_exchange_token=EAACEdEose0cBAKPkEP5zf31S7cfbSXZBJEfNLsgZCZBv2q2laGOg2tipmGWHqnwZBICIZAAKK18UVGRK9AWjZAh4eRac8j9VEOfh7m9gZBOPZBXwOGTKyGMdZAnfbWqSbIufzgY2CPgzN45XCDhN9bsPh7I8bwNIvy0oHJh3rL35CcyyPWpI33R5Jknul2NLUpuHMZD

The result will be something like this:

{"access_token":"EAAUAA6XzH3sBAKty6EU2yZCEmKxJTqOzr3BF5F30ehZA8xxwoWluH6ETjIZAlAcGmtQM3xR4Q9alnzE9osu5kFarHB2avGHHFAMVI2Q0xF62PLeaV8PfrzaMa3YBqMs57a19noZB6s41ziqlbDUImoBWQVDlU3x1msVdsDqulaZsZD","token_type":"bearer","expires_in":5184000}

The alphanumeric string “access_token”, marked in bold, will be the long-lived access token we wanted to get, which, as the expires_in attribute indicates, expires 5,184,000 seconds after being generated, ie 2 months.

5. Get permanent access token

But even though a couple of months is a considerable time, it can be quite tedious to have to repeat this process every 2 months in order to renew access for your applications, so there is still one last step in order to get the permanent access_token that we were pursuing from the beginning, which will no longer be necessary to renew once generated.

So you will get to the following URL from your browser:

https://graph.facebook.com/{page_id}?fields=access_token&access_token={long_lived_token}

That in our example would be:

https://graph.facebook.com/315781431851791?fields=access_token&access_token=EAAUAA6XzH3sBAKty6EU2yZCEmKxJTqOzr3BF5F30ehZA8xxwoWluH6ETjIZAlAcGmtQM3xR4Q9alnzE9osu5kFarHB2avGHHFAMVI2Q0xF62PLeaV8PfrzaMa3YBqMs57a19noZB6s41ziqlbDUImoBWQVDlU3x1msVdsDqulaZsZD

The answer you get will look like this:

{
   "access_token": "EAAUAA6XzH3sBAByxmePXoivAX8DamdhghHUNWEZBxdXnQZAZAUPbDpBrmS6PexVeka3JTL9Vxn8eQe6wBLnlPbsN06nBPhxQhp0tKNrdZALXIEHgVANOb4U2eIz3BRHqTCAjSoFxqVZBWjc9K3qHyyRcGczccU7NRWjj5OkzxbAZDZD",
   "id": "315781431851791"
}

And now, yes, this token linked to the Facebook page with the id that appears in the answer (315781431851791 in our example) is permanent.

6. Verify that the generated token is permanent

You can confirm the generated token is permanent using the Facebook Access Token Debugger:

Depurador access token permanente

If you find it more convenient, you can follow these same instructions through the following video:



 

About the author

Daniel López Azaña
Cloud Solutions Architect

Entrepreneur, a generator of ideas and restless mind. Passionate about new technologies, especially Linux systems and Open Source Software. I also like to write about Technology News, Cloud Computing, DevOps, System Security, Web Development and Programming, SEO, Science, Innovation, Entrepreneurship, etc.

DanielHow to get a permanent token to access a Facebook page

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *