Question

Can any body help how to get the Twitter email I am using this link in php codeigniter here i am getting my information except email. Then how to fetch the email? is there any scope shall we specified in config file?

Was it helpful?

Solution

You can't.

Twitter API does not provide access to a user's email address


Here's a response to this same question from a Twitter employee

The API won't return an email address to you. If you're interested in a user's email address, you'll have to ask the user for it within your own application as a completely distinct act.

OTHER TIPS

I'm a just a few years late to answer this question but I'm going to answer it anyway.

You can!!!

Check the link where this issue has been addressed and answered.

  • Basically, you first need get elevated permissions from the twitter developer account by providing your privacy policy url and the terms of conditions url.

  • Apply this step after getting email access permission from twitter dev support.

    /public_html/application/config/hybridauthlib.php

And add : "includeEmail" => true to the Twitter provider.

"Twitter" => array (
"enabled" => true,
"keys" => array ( "key" => "Your_Twitter_App_Key", "secret" => "Your_Twitter_Secret_Key" ),
"includeEmail" => true,
)

It should be possible now. First, whitelist your app.

https://support.twitter.com/forms/platform70 [I have added a youtube link for DEMO LINK and my app url in github for APPLICATION URL] and clicked on "submit" button.

Next,You will get 1st email from twitter(If you dont get an email from twitter,re-fill the form and send again) saying "Thanks for reaching out".Then after a few hours you get a 2nd email saying that url app is whitelisted.

Once they say that your App is whitelisted, update your App's settings in Twitter Developer portal. Sign in to apps.twitter.com and:

On the 'Settings' tab, add a terms of service and privacy policy URL on the 'Permissions' tab, change your token's scope to request email. This option will only been seen, once your App gets whitelisted.

Next,you may have to regenerate your access token in https://apps.twitter.com .And also use https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true in order to get the user's email address

I was using CodeIgniter version of HybridAuth library, and in this file

app/application/third_party/hybridauth/Hybrid/Providers/Twitter.php

Modifed this line

$response = $this->api->get( 'account/verify_credentials.json' );

to the below one

$response = $this->api->get( 'account/verify_credentials.json',['include_entities' => 'true', 'skip_status' => 'true', 'include_email' => 'true'] );

also, added the below line before returning of user profile

$this->user->profile->email      = (property_exists($response,'email'))?$response->email:"";

and started receiving the email id

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top