简体   繁体   English

Laravel Socialite错误:“必须使用活动访问令牌来查询有关当前用户的信息。”

[英]Laravel Socialite error: “An active access token must be used to query information about the current user.”

I'm using Socialite to authenticate my users via Facebook. 我正在使用Socialite通过Facebook验证我的用户。 However, I can't get it to work. 但是,我无法让它发挥作用。 I followed this tutorial, but I get the following error: 我按照教程,但收到以下错误:

在此输入图像描述

I looked everywhere and tried whatever, but I can't get it to work. 我到处寻找并尝试过任何事情,但我无法让它发挥作用。 Here's my code: 这是我的代码:

In services.php: 在services.php中:

'facebook' => [
    'client_id' => '[My App ID]',
    'client_secret' => '[My App Secret]',
    'redirect' => 'http://localhost:8000/auth/facebook/callback/',
],

My routes: 我的路线:

Route::group(['middleware' => ['web', 'requestlog']], function () {   
    Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider');
    Route::get('auth/facebook/callback/', 'Auth\AuthController@handleProviderCallback');
});

Then in my AuthController: 然后在我的AuthController中:

use Laravel\Socialite\Facades\Socialite;

public function redirectToProvider()
{
    return Socialite::driver('facebook')->redirect();
}

public function handleProviderCallback()
{
    try {

        $providerUser = Socialite::driver('facebook')->user();
        dd('yay it worked!');

      } catch (RequestException $e) {

      dd($e->getResponse()->json());

    }
}

Then I have these settings in FB: 然后我在FB中有这些设置:

在此输入图像描述

在此输入图像描述

What is going wrong? 出了什么问题? I followed all the necessary steps as far as I know. 据我所知,我遵循了所有必要的步骤。 I don't get what's wrong here. 我不明白这里有什么问题。 I hope I provided all the necessary information! 我希望我提供了所有必要的信息!

Edit 编辑

Here's what the url looks like on the page where the error displays: http://localhost:8000/auth/facebook/callback?code=AQBtnKEqZgImLqN7f3hETe9GptgzFH71sXrV5qmv8Rpo6Oj5-4rl8mBjFPbfkBtiV8w9atV7X4OrWfHyalJkXU-k6lkEv1bly6v5Qxm2es-_RRp8gfoSWOZwjqE34Rvq6__L3aEOERPEa9LSBk_rKVP_cYGZoQeAydRLQUZVGdr_p1SuE1hRZIvZTAZ-zorkPoyyCDNZtDEVFHGRJt_c3kTf_AKE97FVemrXrUDzxaX-rvovKtfGF3u4CvAIt5pe4g7zD30jAWF78ZgjjPpr21MdaGwP5V0tc8g84oz0dR5Nbit7sKeUE-XblWFrQCIKfqs-OJ6rcuzw7iPTx6xrQ9Ev&state=4f924a9974207482c6fce24c1d74705c6688adc0#_=_ 这里的网址是什么样子的网页,其中显示错误: http://localhost:8000/auth/facebook/callback?code=AQBtnKEqZgImLqN7f3hETe9GptgzFH71sXrV5qmv8Rpo6Oj5-4rl8mBjFPbfkBtiV8w9atV7X4OrWfHyalJkXU-k6lkEv1bly6v5Qxm2es-_RRp8gfoSWOZwjqE34Rvq6__L3aEOERPEa9LSBk_rKVP_cYGZoQeAydRLQUZVGdr_p1SuE1hRZIvZTAZ-zorkPoyyCDNZtDEVFHGRJt_c3kTf_AKE97FVemrXrUDzxaX-rvovKtfGF3u4CvAIt5pe4g7zD30jAWF78ZgjjPpr21MdaGwP5V0tc8g84oz0dR5Nbit7sKeUE-XblWFrQCIKfqs-OJ6rcuzw7iPTx6xrQ9Ev&state=4f924a9974207482c6fce24c1d74705c6688adc0#_=_

I also tried in incognito mode, removed cookies and so on. 我也尝试过隐身模式,删除cookie等等。 Same result... 结果相同......

I didn't want to mess with access tokens or other API's because I don't think that would be a solution to my problem. 我不想搞乱访问令牌或其他API,因为我认为这不会解决我的问题。 But now (after I don't know how long...) I got it to work! 但是现在(在我不知道多久之后......)我开始工作了! For whoever has this problem as well; 对于有这个问题的人; I did the following steps which out of luck made it work: 我做了以下步骤,运气不好使它工作:

  1. I deleted socialite from composer.json and updated it. 我从composer.json中删除了socialite并更新了它。
  2. I reinstalled socialite. 我重新安装了名媛。 I added the following line in composer.json: "laravel/socialite": "2.*" . 我在composer.json中添加了以下行: "laravel/socialite": "2.*"
  3. Then when I ran the snippet I got the following error: ErrorException in FacebookProvider.php line 89:Undefined index: first_name . 然后,当我运行该片段时,我收到以下错误: ErrorException in FacebookProvider.php line 89:Undefined index: first_name
  4. After that I replaced the code in FacebookProvider.php with this file from github . 之后我用github中的这个文件替换了FacebookProvider.php的代码。

Don't forget to execute random composer dump-autoload 's everytime because sometimes that randomly seems to help as well. 不要忘记每次都执行随机的composer dump-autoload因为有时随机似乎也有帮助。

Now it finally works for whatever reason! 现在它最终无论如何都有效!

EDIT 编辑

I also noticed that composer update does a good job. 我还注意到composer update做得很好。 Update socialite to the newest version if this doesn't work. 如果不起作用,请将socialite更新为最新版本。 This eventually fixed another problem I had recently. 这最终解决了我最近遇到的另一个问题。

Running composer update and then composer dump-autoload solved the issue for me. 运行composer update然后composer dump-autoload为我解决了这个问题。

I noticed Laravel Socialite was updated, so @Markinson is right 我注意到Laravel Socialite已经更新,所以@Markinson是对的

The error you have mentions is about the access_token which is invalid. 您提到的错误是access_token无效。 You need to generate an permanent access token in order to get this thing work. 您需要生成永久访问令牌才能使此功能正常运行。

This is a link you can follow. 这是您可以关注的链接。 ( facebook: permanent Page Access Token? ) and I think you should use direct Http graph api calls to make this things work. Facebook:永久页面访问令牌? )我认为你应该使用直接的Http图api调用来使这个工作。

对我而言,它与composer require laravel/socialite:2.0.21 ...从2.0.20升级

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 必须使用活动访问令牌来查询有关当前用户的信息。 Facebook PHP SDK v4 - An active access token must be used to query information about the current user. Facebook PHP SDK v4 Facebook App Uncaught OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。 抛出 - Facebook App Uncaught OAuthException: An active access token must be used to query information about the current user. thrown 必须使用活动访问令牌来查询有关当前用户的信息 - An active access token must be used to query information about the current user 必须使用活动访问令牌来查询有关当前用户的信息 - An active access token must be used to query information about the current user 必须使用活动访问令牌来查询有关laravel中当前用户的信息 - An active access token must be used to query information about the current user in laravel “必须使用活动访问令牌来查询有关当前用户的信息” facebook错误 - “An active access token must be used to query information about the current user” facebook error 致命错误:未被捕获的OAuthException:必须使用活动访问令牌来查询有关当前用户的信息 - Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user facebook php sdk错误-必须使用活动访问令牌来查询有关当前用户的信息 - facebook php sdk error - An active access token must be used to query information about the current user 必须使用活动访问令牌来查询有关当前用户的信息 访问令牌似乎有效 - An active access token must be used to query information about the current user | Access token seems to be valid OAuthException:必须使用活动访问令牌来查询有关当前用户的信息 - OAuthException: An active access token must be used to query information about the current user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM