Fischer asked this 4 years ago

Laravel Socialite Twitter login return email is null cannot create user

I am using Socialite2.0 with Laravel5.3

Facebook and Google authentication are working well. With twitter, it fails because twitter is not sending back email id. The createOrGetUser() method is failing because email is null.

The error I am getting in laravel.log is 

ERROR: exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: Column 'email' cannot be null' in ....../vendor/laravel/framework/src/Illuminate/Database/Connection.php

How to resolve this?

I understand FB and Google uses OAuth2 while Twitter is OAuth1 and hence things are slightly different.


Best Answer by pseudoFish 4 years ago

Go to twitter developer's console.

In the permissions tab, scroll down to additional permissions.

Check: Request email addresses from users and click Update Settings

When you update, you might get an error that Privacy Policy URL
Terms of Service URL cannot be blank.

Twitter expects you to have static pages with privacy policy and terms of service.

If your website doesn't already have such pages, you can easily create them using free templates available on the web.

Once you have the URLs ready, go to Settings tab and enter them.

Now you can check the option to request emails and save again.


Guest 1 year ago
Like this answer!