get access token facebook graph api
Share this post

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.

If you know nothing about Python, you should start by reading my complete guide on Python for SEO.


Learn Python by subscribing to my Newsletter


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 to much to refresh it every time.

Go to Tools > Access Token Debugger

  1. Paste your token and click on “Debug”.
  2. Click on “Extend Access Token”

If all went well, you should get that message.

You Might Also Like  Intro to GSC API with Python (Video)

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.

Conclusion

This is fantastic.

You are now ready to use Python to post to Facebook groups using the API.