在Socialize laravel 5中发送和检索自定义字段

时间:2016-07-11 07:37:03

标签: php laravel laravel-5.1 laravel-socialite

如何使用此方法在RedirectToProvider方法中在socialized laravel中发送自定义字段:

if ($social == 'facebook') {
    return Socialize::with($social)->fields([
                'first_name', 'last_name', 'email', 'gender', 'birthday'
            ])->scopes([
                'email', 'user_birthday'
            ])->redirect();
}

假设我想发送network_id => 9。

然后我如何在我获取用户信息的处理程序方法中获取它?

$user = Socialize::with('facebook')->user();

2 个答案:

答案 0 :(得分:0)

我发现使用Socialite获取参数的唯一方式是将其存储在会话中

public function redirectToFacebookProvider()
{
    // save anything you will need later, for example an url to come back to
    Session::put('url.intended', URL::previous());

    return Socialite::driver('facebook')->redirect(); 
}

public function handleFacebookProviderCallback()
{
    // handling....

    $url = Session::get('url.intended', url('/'));
    Session::forget('url.intended');

    return redirect($url);
}

获得了答案from https://laracasts.com/discuss/channels/laravel/socialite-return-parameters-in-callback?page=0

答案 1 :(得分:-1)

使用

$user = Socialite::driver('facebook')->user();

然后从$ user数组中检索项目,如此

$user['email']