Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get user email #67

Open
fcristel opened this issue Aug 25, 2015 · 22 comments
Open

Get user email #67

fcristel opened this issue Aug 25, 2015 · 22 comments

Comments

@fcristel
Copy link

I`ve seen that in order for Twitter to let you access user email, you have to ask them for special permission to do so.
I've received the permission, then enabled it under "Additional permissions" on my Twitter app management, but still can't retrieve the email. Is this a problem with this library or is it with Twitter?

@nachojimenez
Copy link

Have you solved it?

I´m waiting for approval so i cannot test, but it says in Twitter docs that you´ll have to forget old tokens for the extra permission to appear.

@fcristel
Copy link
Author

Not solved yet. I just removed the twitter authentication from the site, seeing that it didn't work as it supposed to, waiting to have some time to do more testing.

So you should regenerate the token after the permission was granted? That's all? Tell me if it worked for you after you get the approval please. Thanks!

@nevi-me
Copy link

nevi-me commented Sep 22, 2015

This exists in PR #61 , hopefully @jaredhanson will have some time to look into it.

@serjrd
Copy link

serjrd commented Dec 10, 2015

+1
app whitelisted
would be great to be able to get email through this lib

@nachojimenez
Copy link

You can.. but you have to add a userProfileURL in the authorization strategy..

This is my strategy:

// Twitter OAUTH Strategy
Auth.passport.use(new TwitterStrategy({
        consumerKey: config.get("authentication.twitter.consumerKey"),
        consumerSecret: config.get("authentication.twitter.consumerSecret"),
        userProfileURL: "https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true",
        callbackURL: config.get("authentication.twitter.callbackURL")
    },
    function(token, tokenSecret, profile, done) {
        Login.findOrCreateUser(profile,function(err,user) {
            done(err,user);
        });
    }
));
´´´

@tayste5000
Copy link

That URL doesn't work for me. Looking at the source code it seems like

"?user_id=" + user.id

is being appended to the URL which screws up the request if there is already a "?include_email=true" query string. Is there a particular reason why the "account/verify_credentials" API endpoint isn't being used by this request? Because that would eliminate the need for adding the user ID as a query string...

@nachojimenez
Copy link

Yeah sorry.

I commented that out of the file a long time ago and didn´t remember .

On Sun, Dec 20, 2015 at 8:58 AM, Taylor Stevens notifications@github.com
wrote:

That URL doesn't work for me. Looking at the source code it seems like

"?user_id=" + user.id

is being appended to the URL which screws up the request if there is
already a "?include_email=true" query string. Is there a particular reason
why the "account/verify_credentials" API endpoint isn't being used by this
request? Because that would eliminate the need for adding the user ID as a
query string...


Reply to this email directly or view it on GitHub
#67 (comment)
.

@merciba
Copy link

merciba commented Dec 23, 2015

Has this been resolved? I keep getting 500 "Could not authenticate you." error when trying to get the user profile with email, using @nachojimenez's answer above. Also using a whitelisted app, and have followed all of the steps (add TOS and Privacy Policy page links, check "Additional Permissions" box, etc.)

@tayste5000
Copy link

Did you remove the automatic query string addition in the userProfile function? Also did you create new API keys and secrets after gaining permission and checking the box?

@rodrigogs
Copy link

+1

@MichaelArnoldOwens
Copy link

+1

Thought #61 addressed this, but upon trying email: true and includeEmail: true in options, I still cannot get email after twitter auth.

@jaredhanson
Copy link
Owner

Is your application whitelisted by Twitter for it?

@boycce
Copy link

boycce commented Apr 15, 2016

I can confirm by adding
userProfileURL: "https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true"
alongside granted email permissions from twitter works.

@tambling
Copy link

Wish Twitter would just use scope and profileFields like everyone else, but I can also confirm that changing userProfileURL and having a whitelisted app makes email visible in the JSON that comes back.

@davidwieler
Copy link

davidwieler commented May 3, 2016

@MichaelArnoldOwens no, but you do have to get a new token for each user as it says it "only applies to new logins".

@tambling I'm with ya! so annoying.... however, it does work with userProfileURL, if you've been granted email permissions, which is better than nothing!

IT ALSO works by using includeEmail: true, without the userProfileURL.

here's what I'm using:

    consumerKey     : configAuth.twitterAuth.consumerKey,
    consumerSecret  : configAuth.twitterAuth.consumerSecret,
    callbackURL     : configAuth.twitterAuth.callbackURL,
    includeEmail: true

To get whitelisted, use this URL: https://support.twitter.com/forms/platform, select "I need access to special permissions", then enter "Email" into "Permissions Requested"

@merciba
Copy link

merciba commented May 26, 2016

@boycce's answer worked for me as well. Thanks

@anthonygore
Copy link

I requested whitelisting by going to https://support.twitter.com/forms/platform and got this email in reply:

Thanks for reaching out. Details on Twitter's available special permissions are below:

Email Requesting Permission: Developers can now directly enable email requesting permission for all apps created via apps.twitter.com. To proceed simply log into your app at apps.twitter.com and add links to your Terms and Conditions and Privacy Policy under the Settings tab. Then, check the Request email addresses from users box under the Permissions tab. Please visit our Developers Forum for any technical questions regarding this permission.

Email Requesting Permissions for Fabric Apps: Email requesting permission is only available for apps created via apps.twitter.com. To proceed please create a new key there, and then respond to this email with this new app ID. We will then add Fabric permissions to it.

Currently there is no way to combine apps.twitter.com apps with those created via fabric.io. We appreciate your understanding.

App Cards: Please respond to this email to confirm if you are requesting app card access.

xAuth: xAuth is not currently available. For comprehensive documentation on all of the Twitter API’s authentication and authorization paths, please visit this page on our developer site.

Regards,
Twitter Platform Operations

@rvetere
Copy link

rvetere commented Jan 26, 2017

can confirm: by adding the email permissions to my app and regenerating the consumer key and secret AND by adding this special url to my strategy like this:

export default new TwitterStrategy({
  consumerKey     : process.env.AUTH_TWITTER_CONSUMER_KEY,
  consumerSecret  : process.env.AUTH_TWITTER_CONSUMER_SECRET,
  callbackURL     : process.env.AUTH_TWITTER_CALLBACK_URL,
  userProfileURL  : 'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
  passReqToCallback : true,
},
  (req: Object, accessToken: string, refreshToken: string, profile: Object, done: Function): void => {
...
}

then it just starts working like any other oauth2 passport strategy (i've implemented so far) by giving you a profile.emails[0].value 😉

@heymartinadams
Copy link

@rvetere: closing ) bracket missing from your excellent example

@jesstelford
Copy link

jesstelford commented Jul 3, 2019

@davidwieler's answer is great!

Here are updated steps to add email permissions to a Twitter App in 2019:

  • Visit https://developer.twitter.com/en/apps
  • Click "Details" next your app
  • Ensure "Terms of service URL" and "Privacy policy URL" have values (if not, click "Edit" to add and save them)
  • Click "Permissions" tab
  • Click "Edit"
  • Check the "Request email address from users" option
  • Hit "Save"

Screen Shot 2019-07-03 at 10 58 18 pm

@jawad-aziz-farhad
Copy link

Thanks to @rvetere. Request email address from users option should be checked. and you have to Regenerate the Tokens to get the email value in response.

@salsa-project
Copy link

@davidwieler includeEmail: true Worked for me too .. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests