Laravel Socialite facebook获取用户电话号码

时间:2017-11-30 11:44:30

标签: facebook laravel facebook-graph-api laravel-socialite

我在我的网站上使用laravel socialite身份验证用户。我获得了基本的用户数据,但我需要user_phone,因为有些用户使用电话号码为Facebook注册。 不幸的是,在文档中我没有找到字段phone_number

这是基于screenchot的FB doc,ebout email field:

enter image description here

问题:如果字段电子邮件为空,在哪里查找数字???

2 个答案:

答案 0 :(得分:0)

使用Facebook API检查可用字段https://developers.facebook.com/docs/graph-api/reference/v2.2/user

,无法使用电话号码

答案 1 :(得分:-1)

您可以尝试使用它。积分转到@amirhazz,完整的帖子可以在这里找到:https://laracasts.com/discuss/channels/laravel/socialite-facebook-extra-fields?page=1

class FacebookLogin {

    /**
     * Since facebook will give you name, email, gender by default,
     * You'll only need to initialize Facebook scopes after getting permission
     */

    const facebookScope = [
        'user_birthday',
        'user_location',
    ];

    /**
     * Initialize Facebook fields to override
     */
    const facebookFields = [
        'name', // Default
        'email', // Default
        'gender', // Default
        'birthday', // I've given permission
        'location', // I've given permission
    ];

    public function facebookRedirect()
    {
        return Socialite::driver('facebook')->fields(self::facebookFields)->scopes(self::facebookScope)->redirect();
    }

    public function facebookCallback()
    {
        $facebook = Socialite::driver('facebook')->fields(self::facebookFields)->user();
    }
}
相关问题