简体   繁体   中英

How to get facebook page access_token and use it for webhook leadgen return?

I am using webhooks on lead generation on facebook (PHP Back-END). I have done the tutorial in which they explain how these leads can be retrieved.

I've tested my code and everything works perfectly, except for the fact that my access_token is hard-coded and I want to retrieve it on every request.

I am using this code to access the facebook graph:

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url
));

the url looks like this:

$url = 'https://graph.facebook.com/v2.5/' . $leadgen_id . '?access_token=' . $access_token . '&debug=all&format=json&method=get&pretty=0&suppress_http_code=1';

How can I have the access token automatically , every time the webhook script is called?

You need to generate and store an "Extended Page Token", it is valid forever. There is no way to generate Tokens automatically.

The general procedure:

  • Get a User Token with manage_pages
  • Extend the User Token
  • Get an Extended Page Token with /me/accounts

More information about Tokens:

Update: there are new permissions now, replacing manage_pages :https://developers.facebook.com/docs/pages/overview#permissions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM