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

前端 未结 2 914
轮回少年
轮回少年 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:32

    It worked for me too. Please note its issue at socialite2.0 for laravel 5.2 Just download and update the code. https://github.com/laravel/socialite/blob/2.0/src/Two/FacebookProvider.php

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题