The first step to being able to use the Facebook Graph API is to get your access token.
In this post, we will look at all the steps you need to get a long-lived access token to post in Facebook Groups using the Facebook API and Python.
1. Create an App
Go to Facebook Developers Console and Click on “My Apps”.
There, you will need to create an app with a custom set of permissions.
Add the name of the app and your email and click on “create app”.
2. Generate the Access Token
Now, you will need the access token with the permissions to post of a Facebook Group.
Go to Tools > Graph API Explorer > and click “Generate Access Token”.
3. Add Permissions
Then, click on “Add a Permission” > Events Group Pages > Select “Publish-to-groups”.
You can choose whatever permission that you will need.
Re-generate the Access Token to Allow new permissions by clicking on “Generate Access Token” again.
Copy the Access Token.
4. Generate Long-Lived Access Token
By default, the access token will expire very quickly.
You will want to generate a Long-Lived Access Token so you don’t have to bother too much to refresh it every time.
Go to Tools > Access Token Debugger
- Paste your token and click on “Debug”.
- Click on “Extend Access Token”
If all went well, you should get that message.
5. Test the API
In the Graph API Explorer, make a
POST request to the group ID that I created for the purpose “744128789503859“.
Great! It worked!
6. Save the Token
To use the Graph API from Python, we will need to store the Token.
In a text editor (like Visual Studio Code), create a
credentials.json file that will look like this.
This is fantastic.
Sr SEO Specialist at Seek (Melbourne, Australia). Specialized in technical SEO. In a quest to programmatic SEO for large organizations through the use of Python, R and machine learning.