skip to Main Content

I’m having trouble with the recent facebook update with their API.

I was having an error that said

Laravel FacebookProvider Error. Undefined variable: access_token.

I found another question where they said to do this :

In vendor/laravel/socialite/src/Two/FacebookProvider.php

Replace

parse_str($body, $data);
return $access_token;

With

parse_str($body, $data);
$json = json_decode(key($data));
return $json->access_token; 

After I made those changes, now i’m having this error

FatalErrorException in FacebookProvider.php line 67:
Cannot access empty property

Here’s the link : https://concoura.com

2

Answers


  1. Never, ever modify vendor files. Instead, update your package through composer. This was fixed awhile ago as the FacebookProvider has changed greatly and utilizes a completely different method to retrieve and provide the access code.

     /**
     * {@inheritdoc}
     */
    public function getAccessTokenResponse($code)
    {
        $postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
        $response = $this->getHttpClient()->post($this->getTokenUrl(), [
            $postKey => $this->getTokenFields($code),
        ]);
        $data = [];
        $data = json_decode($response->getBody(), true);
        return Arr::add($data, 'expires_in', Arr::pull($data, 'expires'));
    }
    
    Login or Signup to reply.
  2. I had the same problem and I solved with

    composer require laravel/socialite:^2.0

    Tested with Laravel 5.2 and 5.3

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search