How to Get Your Facebook API Access Token: A Step-by-Step Guide for Developers
By Ed Malaker
While many social media sites like Facebook and X (formerly Twitter) will allow you to schedule posts in advance now, it’s still a tedious process that requires you to enter the posts one at a time, and if you have multiple accounts, you will need to log in and out of each one, which can be time-consuming. Another problem when trying to grow your social media account is the limited analytics provided by these sites.
Fortunately, we can solve both of these problems using an API(Application Programming Interface) and a simple Python script or similar program. Facebook offers a free API that works on Facebook and Instagram, so keep reading while we explain how to get it and what you can do with it.
What is the Facebook API?
The Facebook API provides developers with tools to interact with Facebook’s platform programmatically to retrieve data, post content, manage ads, analyze audience insights, and much more. Facebook’s APIs include the Graph API, Marketing API, and specialized endpoints for various services like Messenger and Live Video. Right now, we are going to get the Graph API, but the others are the same.
Steps to acquire the Facebook API
Create an app
Create a developer account at Meta for Developers (facebook.com)
Once you have an account, visit the Meta for Developers home page and select My Apps from the top right of the screen.
The next screen will show you any apps you have already created, if any, and you should see a green Create App button that you want to click.
The next screen will ask you if you want to connect a business portfolio, or you can select – I don’t want to connect a business portfolio yet.
The next page has several options, but for now, we can select – Other.
The next page will ask you to select an app type, and we can select – Business.
On the next page, you will add an app name, enter an email, and choose – No business portfolio selected.
Choose – Create app, then reenter your password.
You will now see a page that asks you to add products to your app. Choose – Instagram (which will work with Facebook) by clicking “Set up.”
On the left side of the next screen, select – API setup with Facebook login. Then select “add product” to go back to the original screen.
Now you want to add Facebook Login for Business by clicking “Set up.” Then, “Save changes.”
Review app features
After you create your app, you can review its features and permissions by selecting “App Review” on the left side of the screen and then choosing – Permissions and Features. Most have standard access, and we are going to leave them for our purposes, but you may need to change some of these to advanced access if a lot of people will be using the app. To use advanced access, you will need to verify your business.
Generate your access token
You will need to enter the access token into your Python script or other coding project to make posts, look at stats, and more using the app we just created. To get the token, follow these steps:
Choose “Graph API Explorer” under “Tools” at the top of the page.
Ensure that the app you just created is the “Meta App” on the right side of the screen.
Directly under that, you will need to add the permissions you want to use from the review app section. You can choose as many as you want by typing in the name or using the drop box, but for now, we’ll just go with pages_show_list, Instagram_content_publish, and Instagram_basic. These are the things you will be able to do using your Python script or other code, so take time to go through them and get what you need.
When the permissions are selected, click – Generate Access Token
Next, you will see a list of all of the pages the app can potentially access. If you have several, you can select them individually or choose “Opt in to all current and future Pages” to allow your app and scripts to access everything. After choosing, you will do the same for Instagram pages.
You will then review the app and click save.
You will now see your access token near the top right of the screen, and you can copy it to use in your scripts. However, it only lasts a few hours before you’ll need to regenerate it by clicking generate access token. To make it last about two months, copy the access token and open “Access Token Debugger” under “Tools” at the top of the page.
Paste your token into the empty field on the new page and click – Debug
Next, click Extend Access Token for the new access token that you can use in your projects.
YOU DID IT!
This guide is part of our larger guide about DIY Python programming
Follow GeekSided to learn more about APIs and how to use them.