Alex Besleaga
Alex Besleaga

Reputation: 61

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?

Upvotes: 1

Views: 2253

Answers (1)

andyrandy
andyrandy

Reputation: 74004

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

Upvotes: 1

Related Questions