Abel D
Abel D

Reputation: 1080

Laravel Socialite returns error Undefined index: first_name

Using laravel-socialite I am trying this code

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

But it returns error

ErrorException in FacebookProvider.php line 90: 
Undefined index: first_name

I have laravel/socialite version ^2.0 required in composer.

How to solve this?

Upvotes: 2

Views: 2922

Answers (2)

melanholly
melanholly

Reputation: 772

You can set the array of fields that you want to retrieve from facebook by calling the fields(array $fields) method of the facebook provider.

Here is an example of that

//get the driver and set desired fields
$driver = Socialite::driver('facebook')
                ->fields([
                    'name', 
                    'first_name', 
                    'last_name', 
                    'email', 
                    'gender', 
                    'verified'
                ]);
// retrieve the user
$user = $driver->user();

For reference on the fields names: https://developers.facebook.com/docs/graph-api/reference/user/

Upvotes: 1

Abel D
Abel D

Reputation: 1080

I just have to update the new FacbookProivder.php file which I got from this question.

Here is the file. courtesy German for the answer.

Upvotes: 3

Related Questions