Daniel López Azaña

Theme

Social Media

Blog

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

How to get a permanent token to access a Facebook page

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

2. Create a FB App for your page

2.1 Go to My apps.

2.2 Create new app, for example AppMipagina:

Steps to create a new Facebook App

2.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:

Facebook App administration page

3. 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).

Facebook API Graph Explorer

4. 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=<strong>{app_id}</strong>&client_secret=<strong>{app_secret}</strong>&fb_exchange_token=<strong>{short_lived_token}
</strong>

That in our example would look like this:

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

The result will be something like this:

{"access_token":"<strong>EAAUAA6XzH3sBAKty6EU2yZCEmKxJTqOzr3BF5F30ehZA8xxwoWluH6ETjIZAlAcGmtQM3xR4Q9alnzE9osu5kFarHB2avGHHFAMVI2Q0xF62PLeaV8PfrzaMa3YBqMs57a19noZB6s41ziqlbDUImoBWQVDlU3x1msVdsDqulaZsZD</strong>","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/<strong>{page_id}</strong>?fields=access_token&access_token=<strong>{long_lived_token}
</strong>

That in our example would be:

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

The answer you get will look like this:

{
   "access_token": "<strong>EAAUAA6XzH3sBAByxmePXoivAX8DamdhghHUNWEZBxdXnQZAZAUPbDpBrmS6PexVeka3JTL9Vxn8eQe6wBLnlPbsN06nBPhxQhp0tKNrdZALXIEHgVANOb4U2eIz3BRHqTCAjSoFxqVZBWjc9K3qHyyRcGczccU7NRWjj5OkzxbAZDZD</strong>",
   "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:

Facebook Access Token Debugger

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

Facebook
Daniel López Azaña

About the author

Daniel López Azaña

Tech entrepreneur and cloud architect with over 20 years of experience transforming infrastructures and automating processes.

Specialist in AI/LLM integration, Rust and Python development, and AWS & GCP architecture. Restless mind, idea generator, and passionate about technological innovation and AI.

Related articles

JAMstack Architecture - JavaScript APIs Markup

What is JAMstack? Modern Architecture for Ultra-Fast Websites

Discover how JAMstack revolutionizes web development with pre-generated static sites served from global CDN. Exceptional speed, improved security, unlimited scalability, and minimal hosting costs compared to traditional CMS platforms.

November 3, 2025
User database icon

ᐈ How to create a user in MySQL/MariaDB and grant permissions on a specific database

Creating a MySQL or MariaDB user and granting permissions to him to access a specific database and be able to write data on it is a very usual task that is necessary to perform each time you install a new application based on any of these database engines, like web applications running on top of LAMP stack. Whether it is a simple WordPress, or a more complex application tailor made, one way or another you will always have to complete these steps at some point before its deployment.

June 3, 2017
sugarcrm-logo-100068038-large

SugarCRM error when searching tasks related to custom modules with underscores within their names

When we create a custom module in SugarCRM (eg «grt_Providers_Contracts») and create a link or relationship between that module and one that uses the «Related to» field type such as «Tasks», we probably will want to search all the tasks related to our new module «grt_Providers_Contracts» from the simple or advanced search form from «Tasks» module.However, there is a bug in SugarCRM that prevents us to retrieve tasks related to a custom module if that module has underscores (_) within his name, showing the following fatal error:

November 19, 2012

Comments

Joe Tan June 1, 2018
Thanks man, it helped me.
Alex December 4, 2018
If you cant get the permanent access token make sure your app is in development mode.
Abel October 28, 2020
Hola, puedo hacer esto para una página que no sea mía? O sea, quiero verificar por PHP cuando cierta página (que no me pertenece) esté transmitiendo en vivo. ¿Será posible?

Submit comment