我想将facebook与我的应用集成。我使用laravel / socialite包来访问Facebook页面。它完全有效,但我已经登录用户,我希望将他的Facebook个人资料中的信息添加到现有帐户。我使用Oauth 2通过用户凭据登录laravel应用程序,因为它是Angular / Laravel应用程序。我需要检索登录用户以将信息添加到他的帐户,但我无法获得登录的用户ID。我需要在facebook回调路由中将额外参数传递给get
方法。我的问题是有没有办法为facebook回调网址添加额外的参数?这就是我所拥有的:
Route::group(['middleware' => ['web']], function () {
Route::get('/facebook/login', function(){
Config::set('services.facebook.redirect', 'http://taggers.dev/facebook/callback?access_token='.Session::get('access_token'));
return Socialite::driver('facebook')->with(['asdadad' => 'asd'])->redirect();
});
Route::get('facebook/callback', ['middleware' => ['oauth', 'oauth-user'], function(Authorizer $authorizer){
$user = Socialite::driver('facebook')->user();
$uid = $user->getId();
if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error');
$profile = Profile::whereUid($uid)->first();
if (empty($profile)) {
// $user_id= Authorizer::getResourceOwnerId(); // the token user_id
$auth_user = User::where('idUser', $user_id)->first();
$profile = new Profile();
$profile->uid = $uid;
$profile->username = $user->getName();
$profile = $auth_user->profiles()->save($profile);
}
dd($auth_user);
}]);
});
这是我的错误:
Client error: `GET https://graph.facebook.com/oauth/access_token?client_id=1001186793295886&client_secret=b792ea0354c3846225bc70ac7185e54f&code=AQA1xjbQ25a9qE0loN-yjhmOBYBZLtNVcnCLIeCwJV1enion4ysKkpuBqBmZLhpT2I4VkemXr6R9IwcgSVVzqOLMmzvz_SHga9KrK3ny5cLGi0VGmEibNqGSHA9B9jJ9aFt6vA8lQ1r0IqdN94S-KFjpBimzVmT1OoeI-pCayVRG_v_6uYzeQfZAtDXh3BDVTutLaDXUdJEY3sQhop7Qr8n6jARGBYRZgDcXS6Ci69vY3aRoCLsrFdAQlD7Kid0W9QqeSBxbWrc76Ldp06PtdVLMRdQ54qQepwG4mOhOiy40-azn3YIBriSx7o0PcNBBE_f_8vmnbiESlo7R-8Su_7vs&redirect_uri=http%3A%2F%2Ftaggers.dev%2Ffacebook%2Fcallback` resulted in a `400 Bad Request` response:
{"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you (truncated...)