Get user access token with permission via php with FB sdk 3.2

818 views Asked by At

I'm admin of a page and I have my app with ID and Secret. When I go to Graph api Explorer I can easily take my User Access Token with permission "manage-pages". I need to take the same via php, using the FB sdk 3.2. I managed to run only this:

    require 'src/facebook.php';
    $facebook = new Facebook(array(
        'appId'  => 'My app ID',
        'secret' => 'My app secret',
    ));

    //This token is: "My app ID|My app secret"
    print_r($facebook->getAccessToken());

How Can I get the user access token with permission via php with fb sdk 3.2?

Can somebody help me? Thank you!

2

There are 2 answers

0
andyrandy On BEST ANSWER

You need to generate a Login URL and redirect Users to that one, it´s explained in the docs for 3.x.x: https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/

With manage_pages, it would be like this:

$params = array(
  'scope' => 'manage_pages',
  'redirect_uri' => 'https://www.myapp.com/post_login_page'
);

$loginUrl = $facebook->getLoginUrl($params);

I highly suggest upgrading to a server with PHP 5.4+ though.

1
Tobi On

You shouldn't waste your time with using an outdated version of the PHP SDK, or is there a reason why you chose the old version?

See

on how to implement Facebook Login.