0

How to get a Facebook User and Page access key that is valid for more than a few hours or 60 days.

This access key can be used to programmatically get the latest posts from a Facebook page.

There is a lot of information available on the Facebook for developers documentation page but imo it is a bit all over the place.

4

1 回答 1

1

After some hours of searching I figured out how to get a permanent access key.

General Information

At first it seems like Facebook offers 4 kinds of access keys:

  • Short lived user access key (1-2 hours)
  • Long lived user access key (~60 days)
  • App access key
  • Page access key

Facebook for developers documentation

After playing around with this for a while using the Graph API explorer as well as curl and having seen that I can do with it what I want, I was still bothered by the fact that they only last for a given time.

How to create a permanent access key

For the approach I found you need a Facebook Business account that has access to the page you want a key for.

You then need to create a system user as detailed here: Add system user. The following may not be 100% accurate, as my Facebook is in German and thus everything Facebook related is in German as well. (At the time of writing the below is accessible via business.facebook.com/settings)

  • Go to your Business Account Dashboard
  • Go to Settings (Left bottom corner, the cog)
  • Go to More Business Settings or Advanced Settings (The cog, 4th point, beneath Business Assets)
  • Go to Users > System User

Here you can add a system user. Once this is done, you can assign assets (the app and the page you want the key for) and permissions. You can now generate an access key which will be permanent. This key needs to be copied and saved, as it will not be available later on in the interface i.e. it is not saved by Facebook.

You now have a permanent user access key!

Getting a permanent page access key is now as simple as making a GET request with this key:

curl -X GET "https://graph.facebook.com/{PAGE-ID}?fields=access_token&access_token={USER-KEY}"

Replacing {PAGE-ID} with the numeric or textual ID of the page and {USER-KEY} with the key you generated earlier.

于 2021-12-03T08:32:22.570 回答