2

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?

Abel D
  • 1,040
  • 1
  • 18
  • 30
  • what are you returning?. try `dd($user)` to check what they it return. – ssuhat Jan 11 '16 at 10:45
  • i am trying to get the user by `$user = Socialite::driver($type)->user();`. which gives me error. How can I dump $user before that? – Abel D Jan 11 '16 at 10:47
  • dump it before return statement. – ssuhat Jan 11 '16 at 10:50
  • Sorry I still newbie. the only statement I have in that method is `$user = Socialite::driver($type)->user();` If I dump before this statement I get error undefined variable. – Abel D Jan 11 '16 at 10:54
  • dumping $user before returning gives me 'name' and 'id'. – Abel D Jan 11 '16 at 11:23

2 Answers2

3

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.

Community
  • 1
  • 1
Abel D
  • 1,040
  • 1
  • 18
  • 30
1

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/

melanholly
  • 762
  • 1
  • 9
  • 20