【问题标题】:Unable to retrieve email id of twitter using passportjs无法使用 passportjs 检索 Twitter 的电子邮件 ID
【发布时间】:2018-08-25 02:08:11
【问题描述】:
const TwitterStrategy = require('passport-twitter').Strategy;

module.exports = (passport, User) => {
  passport.use(new TwitterStrategy({
    consumerKey: 'paLCHei1bz8uG5mzNK3ZmvWy7',
    consumerSecret: 'djwTrPntW6T2hm3EJ6eIvUrqObMSymgKn6B1foMQyNeypjtbIK',
    callbackURL: 'http://localhost:3000/auth/twitter/callback',
    passReqToCallback: true
  }, (req, accessToken, tokenSecret, profile, done) => {
    User.findOne({ 'twitter.id': profile.id }, (err, x) => {
      if (x) return done(null, x);
      var user = {
        image: profile._json.profile_image_url,
        displayName: profile.displayName,
        email: profile.emails[0].value,
        twitter: {
          id: profile.id,
          email: profile.emails[0].value
        }
      };
      User.create(user, (err, x) => done(null, x));
    });
  }));
};

【问题讨论】:

  • 欢迎来到 Stack Overflow!请阅读How to Ask 页面并更新您的问题。

标签: email twitter oauth passport.js


【解决方案1】:

您需要在 Twitter 上的应用权限中选中“向用户请求电子邮件地址”复选框。你可以阅读更多关于它here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多