artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Facebook Login Failed "Undefined index: access_token"

ppeinsold opened this issue · comments

Hi!
Sometimes I have problems with the Facebook Login. Then I get the following message:

Message: Undefined index: access_token [] []
exception 'ErrorException' with message 'Undefined index: access_token' in .../vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php:171
.../vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php(171): Illuminate\Exception\Handler->handleError(8, 'Undefined index...', '/var/www/...', 171, Array)
#1 .../vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/AbstractService.php(127): OAuth\OAuth2\Service\Facebook->parseAccessTokenResponse('{"error":{"mess...')

The exception happens when I call the following function in my controller:
$token = $fb->requestAccessToken( $code );

Please help. It is really anoying loosing users because login does not work sometimes!
Thanks!

I same problem. but when i print_r before get accesstoken it show error on below

vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php
print_r($responseBody);
exit();
parse_str($responseBody, $data);

"message":"Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings"

Please help me.

@userhuman The error message tells you exactly what you have to do. Every Facebook App has allowed Domains for API calls - you have to enter all domains you are using for API calls and after this it should work.

@Gummibeer I so many try to do. I call every link is related but it's not work.

One month before it's work. but now I checked it can not login with facebook.

You have anyway for fix it. I will thank you so much.

Now it work. Thank

@peiphb02 This issue was resolved in lusitanian/oauth dependency. The problem was that in the previous version, the lib was using parse_str($in, $out); The fix made was to use json_decode. A fork I made has the new version, you can use it yourself by editing your composer.json:

"require": {
     //...
    "artdarek/oauth-4-laravel": "dev-master as dev-lusitanianversion"
  },

 "respositories": [
    {
      "type": "vcs",
      "url": "https://github.com/alexescg/oauth-4-laravel"
    }
  ]

You can then install it by using
composer update --with-dependencies

commented

Thanks.I installl by using composer update its run on laravel 4.2

@artdarek can we have this merged on repo ?

Thanks @artdarek - I've seen you merged @alexescg update.

For those like me arriving here with the issue, here is how I updated my app:

  • at composer.json I had to enforce @dev against minimum-stability:
    "artdarek/oauth-4-laravel": "dev-master@dev",
  • at command-line, run composer to update the package including dependencies:
composer update artdarek/oauth-4-laravel --ignore-platform-reqs --with-dependencies

The important snippet is --with-dependencies. The --ignore-platform-reqs was necessary for me due to other configurations.

Hello you need to change the line 162 in the follow file vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Facebook.php:

parse_str($responseBody, $data);

To this one:

$data = json_decode($responseBody, true);

This work's for me!!