Node.js 使用twitter登录

Node.js 使用twitter登录,node.js,twitter,oauth,Node.js,Twitter,Oauth,我正在尝试在我的node.js应用程序中使用Twitter实现SingIn。首先我打电话给https://api.twitter.com/oauth/request_token,推特给我oauth\u令牌,然后我打电话给https://api.twitter.com/oauth/authenticate?oauth_token=TWITTER_OAUTH_TOKEN打开一个新窗口,显示用户可以接受此应用进行登录。用户接受后,twitter使用oauth\u令牌和oauth\u验证程序调用回调ur

我正在尝试在我的
node.js应用程序
中使用Twitter实现SingIn。首先我打电话给
https://api.twitter.com/oauth/request_token
,推特给我
oauth\u令牌
,然后我打电话给
https://api.twitter.com/oauth/authenticate?oauth_token=TWITTER_OAUTH_TOKEN
打开一个新窗口,显示用户可以接受此应用进行登录。用户接受后,twitter使用
oauth\u令牌和
oauth\u验证程序调用
回调url
。现在我调用
https://api.twitter.com/oauth/access_token
获取
访问\u令牌
。我得到的
access\u token
和给定的格式一样

{ 
   oauth_token: 'NEW_TWITTER_OAUTH_TOKEN',
   oauth_token_secret: 'NEW_TWITTER_OAUTH_TOKEN_SECRET',
   user_id: 'TWITTER_USER_ID',
   screen_name: 'TWITTER_SCREEN_NAME',
   x_auth_expires: '0' 
}
现在我正在尝试获取更多的用户信息,如
user\u电子邮件、user\u pic等
。我正在调用以下api
https://api.twitter.com/1.1/account/verify_credentials.json
具有以下参数:

 let hmac = crypto.createHmac('sha1', 'thisIsTest');
 hmac.update(uuid.v4());
 let hash = hmac.digest('hex');

 var profileOauth = {
    oauth_consumer_key: 'twitter_consumer_key',
    oauth_nonce: uuid.v4(),
    oauth_signature_method:'HMAC-SHA1',
    oauth_signature: hash,
    oauth_timestamp: Date.parse(new Date()),
    oauth_version: '1.0',
    oauth_token: 'twitter_accessToken_oauth_token'
  };

  request.get({
    url: 'https://api.twitter.com/1.1/account/verify_credentials.json',
    // qs: { include_email: true },
    oauth: profileOauth,
    json: true
  }, function(err2, resp, profile) {

    console.log("profile 1 :  ", profile);
    res.json(profile);

  });
我得到了以下错误:

  profile 1 :   { errors: [ { code: 215, message: 'Bad Authentication data.' } ] }
有什么建议吗??提前谢谢

var profileOauth = {
oauth_consumer_key: 'twitter_consumer_key',
oauth_nonce: uuid.v4(),
oauth_signature_method:'HMAC-SHA1',
oauth_signature: hash,
oauth_timestamp: Date.parse(new Date()),
oauth_version: '1.0',
oauth_token: 'twitter_accessToken_oauth_token'
};
试着用这个替换上面的代码

var profileOauth = {
oauth_consumer_key: 'twitter_consumer_key',
oauth_consumer_key_secret: 'twitter_consumer_key_secret', //add consumer_key secret
oauth_nonce: uuid.v4(),
oauth_signature_method:'HMAC-SHA1',
oauth_signature: hash,
oauth_timestamp: Date.parse(new Date()),
oauth_version: '1.0',
oauth_token: 'twitter_accessToken_oauth_token',
oauth_token_secret: 'oauth_token_secret' // add oauth_token_secret
};
我认为您忘记在参数列表中包含应用程序使用者密钥机密和用户oauth令牌机密

试着用这个替换上面的代码

var profileOauth = {
oauth_consumer_key: 'twitter_consumer_key',
oauth_consumer_key_secret: 'twitter_consumer_key_secret', //add consumer_key secret
oauth_nonce: uuid.v4(),
oauth_signature_method:'HMAC-SHA1',
oauth_signature: hash,
oauth_timestamp: Date.parse(new Date()),
oauth_version: '1.0',
oauth_token: 'twitter_accessToken_oauth_token',
oauth_token_secret: 'oauth_token_secret' // add oauth_token_secret
};
我认为您忘记在参数列表中包含应用程序使用者密钥机密和用户oauth令牌机密