Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook Laravel社交名流获取有关用户位置的更多信息_Facebook_Laravel_Laravel Socialite - Fatal编程技术网

Facebook Laravel社交名流获取有关用户位置的更多信息

Facebook Laravel社交名流获取有关用户位置的更多信息,facebook,laravel,laravel-socialite,Facebook,Laravel,Laravel Socialite,当用户登录时,我想要facebook上的其他字段,如user\u location 现在我知道我需要提交一个应用程序进行审查,以便获得获取用户位置的批准。Facebook也已经批准了这项计划 现在,我尝试使用以下代码获取: $this->socialite->driver($provider)->scopes(['user_location', 'user_hometown'])->redirect() 但当我扔掉这个: $this->socialite->

当用户登录时,我想要facebook上的其他字段,如user\u location

现在我知道我需要提交一个应用程序进行审查,以便获得获取用户位置的批准。Facebook也已经批准了这项计划

现在,我尝试使用以下代码获取:

$this->socialite->driver($provider)->scopes(['user_location', 'user_hometown'])->redirect()
但当我扔掉这个:

$this->socialite->driver($provider)->user();
它不提供用户数据数组中的用户位置。但当我第一次尝试登录时,facebook要求获得许可

这是我得到的数据:

User {#330 ▼
  +token: "xxxxxxxxxx"
  +refreshToken: null
  +expiresIn: "xxxxx"
  +id: "xxxxxx"
  +nickname: null
  +name: "xxxxxx"
  +email: "xxxxxx@xx.com"
  +avatar: "xxxxxx"
  +user: array:5 [▶]
  +"avatar_original": "xxxxxxxx"
}
因此,我可以知道,我做错了什么,以及如何获得用户位置

提前感谢大家

您可以在重定向方法中使用fields()方法来设置其他字段,并在以后的应用程序中使用它们

public function redirectToFacebook()
{
    return $this->socialite->driver($provider)->fields([
        'first_name', 'last_name', 'email', 'gender','location'
    ])->scopes([
        'user_location'
    ])->redirect();
}
然后稍后通过以下方式访问它们:

public function handleFacebookCallback()
{
    $providerUser = $this->socialite->driver($provider)->fields([
        'first_name', 'last_name', 'email', 'gender', 'birthday','location'
    ])->user();

    dd($providerUser);
}
请注意,fields()将覆盖默认值,因此在上面的示例中,您不会获得用户的“已验证”和“链接”属性