Member-only story

Python HOW: Making Facebook API calls Using facebook-sdk

Gabriel Harris Ph.D.
4 min readDec 3, 2018

Learn how to obtain a permanent Page Access Token for your pages using the official facebook-sdk package. Updated Oct 2020

Photo captured by the author from developers.facebook.com

Our aim in this article is to get a Permanent Token. We will get a Short-Lived Token manually only once, then use Python to exchange that Token with a Permanent one. FB states that:️

You should not depend on these tokens lifetimes remaining the same as Access Tokens can be invalidated or revoked anytime 💀

This might be the case if we make frequent requests using the same Token. Therefore, at the start of each API calling session, we should run the Python code to refresh our Permanent Token

TL;DR: full code

Create an account for developers 🎡

To do this, you only need to be a verified Facebook user. Go to the developers pagecreate an accountMy AppsCreate AppManage Business Integration ▶ Fill in the App details

I called my App Python

Get a Short-Lived User Token 🍺

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Gabriel Harris Ph.D.
Gabriel Harris Ph.D.

Written by Gabriel Harris Ph.D.

I’m an End-to-End Lead Data Scientist and Data Science Manager. My articles are love letters to my future self

Responses (8)

Write a response

Hi Gabriel, I get the error message: No module named 'facebook'. Any idea how I can resolve this?

God, goat, beautiful, i love you!

hey when i tried to extend the user access short lived token i get that json response with the access token and expiry seconds which is 5182xxx but then when i go to that 'open access tool' debugger page and enter the access token which i extended…