login使用Twitter

我试图在我的node.js app 使用Twitter实现SingIn 。 首先,我打电话给https://api.twitter.com/oauth/request_token给我oauth_token ,然后打电话给https://api.twitter.com/oauth/authenticate?oauth_token=TWITTER_OAUTH_TOKEN打开一个新窗口这表明用户可以接受这个应用程序signIn。 用户接受后,twitter用oauth_tokenoauth_verifier调用一个callback url 。 现在我打电话https://api.twitter.com/oauth/access_token获取access_token 。 我得到access_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_email, user_pic etc 。 我使用以下参数调用以下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.' } ] } 

任何build议? 提前致谢。

 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' }; 

尝试用这个replace上面的代码

 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 }; 

我想你忘了在你的参数列表中包含应用程序用户密钥和用户密码。