Reputation: 111
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.
Upvotes: 3
Views: 3934
Reputation: 111
After some hours of searching I figured out how to get a permanent access key.
At first it seems like Facebook offers 4 kinds of access keys:
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.
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)
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.
Upvotes: 4