Extend Facebook Open Graph Token For Posting to Pa

2019-03-17 09:27发布

问题:

I'm using this tutorial (from the first answer on that page).

In short it uses a FB app, and PHP CURL GET to post to your Facebook page via HTTP. I have it working and can post to my page (as my page) with the correct token.

However, the page access token only lasts an hour, meaning you have to constantly re-authorize by generating a new token. How can I set-and-forget, or otherwise extend my token? I have read the facebook documentation but can't apply it to my scenario.

I just want to authorise once, receive a token and have my web form be able to post to my page.

回答1:

You get your page access token when you (the admin user) authenticate. The page token is based on your short-lived user token. In order to get a long-lived page token you need to get a long-lived user token. They usually last around two months.

Here's how you get a long-lived page token.

  1. Get a short-lived user token.
  2. Get your app ID and app secret.
  3. Make the following GET call: https://graph.facebook.com/oauth/access_token&grant_type=fb_exchange_token&client_id={app-id}&client_secret={app-secret}&fb_exchange_token={short-lived-token}.
  4. Now use the token returned from step 3 to create a new long-lived page token.


回答2:

The & symbol should be replaced with ? (question mark). Then it should work.

ex:

https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id={app-id}&client_secret={app-secret}&fb_exchange_token={short-lived-token}