How to get birthday gender and religion information using laravel socialite implementing facebook Api

前端 未结 2 923
轮回少年
轮回少年 2020-12-21 14:00

I just started using laravel, I am using laravel socialite.

I am able to get username and other data by using following code. But how do I get other data like birthd

2条回答
  •  长情又很酷
    2020-12-21 14:34

    In socialite redirect to facebook method :

        public function redirectToFacebook()
        {
            return Socialite::driver('facebook')->fields([
                'first_name', 'last_name', 'email', 'gender', 'birthday'
            ])->scopes([
                'email', 'user_birthday'
            ])->redirect();
        }
    

    To get the birth date.

    Then to use it in your own models :

        public function handleFacebookCallback()
        {
            $facebook_user = Socialite::driver('facebook')->fields([
                'first_name', 'last_name', 'email', 'gender', 'birthday'
            ])->user();
        }
    

    Note: it will ask for the user to accept sharing their birth date when they connect to Facebook though.

提交回复
热议问题