'Laravel 5.2 Socialite Retrieve Null Email
i'm new to Laravel and i'm trying to make a social auth. I have seen some tutorials and I've got to retrieve user id, profile pic and name from Facebook. My problem is the email, it comes null.
My current object is this:
User {#195 ▼
+token: "EAACYY1xBrzcBAO9KZAjZAZAZBQHWhbtZAb9lIXvH9Y6miRUiABImupk3ZCzHRxy2ZBxc9DU8f1ZAcrw0NEVMmy3GOQMSSyrmDTvMPyREvGm4pA1Ok6zI85LxES4Huy2ZCsxIUr2ISbLreLIv1ZACItUUoqqAnvVPyR4s0ZD"
+id: "989087311199546"
+nickname: null
+name: "MyName"
+email: null
+avatar: "https://graph.facebook.com/v2.2/mypicturecode/picture?type=normal"
+"user": array:2 [▼
"name" => "MyName"
"id" => "MyId"
]
}
and my controller is:
class FacebookController extends Controller
{
public function facebook()
{
return Socialite::driver('facebook')
->scopes(['email'])->redirect();
}
public function callback()
{
$user = Socialite::with('facebook')->user();
return dd($user);
// $user->token;
}
}
I recently discovered something. I have "guzzlehttp/guzzle": "~4.0" in my composer to avoid the cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) error. When the guzzle 4.0 is installed, Laravel Socialite returns to the 2.0.4 version. Looks like the 2.0.18 version deals with the email and first_name/last_name problem. The problem is that when guzzle 4.0 is installed, it requires the socialite 2.0.4
Solution 1:[1]
To receive the email from your Facebook profile, you need to change the "email permission" from "standard access" to "advanced access".
Link: https://developers.facebook.com/apps/<app-id>/app-review/permissions/
Once you save permission, you will start receiving the email in the payload.
Solution 2:[2]
Facebook users can register using a phone number instead of an email address. This means that facebook does not have an email address for that user.
And you might have own privacy policy.
Have a look at this : https://developers.facebook.com/docs/facebook-login/permissions#reference-email
Solution 3:[3]
If you are using laravel 5.2 and socialite 2.0 . Then you would face this issue. It's a bug in socialite. Replace it with the code given below . Path : vendor\laravel\socialite\src\Two\
https://github.com/laravel/socialite/blob/2.0/src/Two/FacebookProvider.php
Then below code would provide you complete details
return Socialite::driver('facebook')->fields([
'first_name', 'last_name', 'email', 'gender', 'birthday'
])->scopes([
'email', 'user_birthday'
])->redirect();
Solution 4:[4]
Just you need to add more permissions to whatever data you want from Facebook object about your user
facebook api url
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shivam Kumar Dwivedi |
Solution 2 | Green Sand |
Solution 3 | insoftservice |
Solution 4 | Hussam Adil |