Error in facebook library. "Malformed access token"

Asked

Viewed 58 times

0

I am trying to get the contact information of the facebook user. For this I am using the Facebook PHP SDK.

I can generate the login url correctly. However, when I try to get the information I get the error "Malformed access token".

The code I’m currently trying is:

$code = Input::get('code'); // Código que vem na queryString

Session::put('facebook', Input::all());

$facebook = $this->facebook_api_instance();

// Aqui é onde eu passo o código OAuth2 e é gerado um erro
$request = $facebook->request('GET', '/me/friends', [], $code);

$response = $facebook->getClient()->sendRequest($request);
  • You have to generate a Token and put in the URL in the code. Type like this: &access_token=$authToken. This variable $authToken is from something similar that I did here that contains a token that I generated on Facebook Developer.

  • Oh I get it. I thought it was something to do with the Facebook Token. Okay!

1 answer

0


I found out what it was.

Is that Facebook uses the native PHP session internally to save two data coming from the url, which is the state and the code. But the Laravel, which is the framework I use, does not use the native PHP session.

I refused to give one session_start only on behalf of this library.

I created an adaptation for the library, to use the Laravel session.

http://github.com/wallacemaxters/facebook

Now it’s working, as expected!

Example:

$api_data = Config::get('facebook_api');

$facebook = new Facebook([
    'app_id'                  => $api_data['app_id'],
    'app_secret'              => $api_data['app_secret'],
    'persistent_data_handler' => new Laravel3SessionPersistentData,
]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.