【问题标题】:How do I make a twitter OAuth Echo verification call?如何进行 twitter OAuth Echo 验证调用?
【发布时间】:2015-02-12 13:10:28
【问题描述】:

我正在使用这个 npm 包对 twitter 的用户进行 OAuth Echo 验证:https://github.com/ciaranj/node-oauth

有没有人举例说明如何使用这个包来验证用户的凭据?

据我所知,我从 iOS 应用程序中正确获取了 X-Auth-Service-Provider 和 X-Verify-Credentials-Authorization,但是我在使用这个包中的这些标头时遇到了问题。

这是 OAuthEcho 构造函数:

var oauthEcho = new OAuthEcho(
        "https://twitter.com",
        "https://api.twitter.com/1.1/account/verify_credentials.json",
        app.config.twitter.consumer_key,
        app.config.twitter.consumer_private_key,
        "1.0A",
        "HMAC-SHA1"
    );

任何帮助将不胜感激!

谢谢!!

【问题讨论】:

    标签: node.js twitter twitter-oauth


    【解决方案1】:

    哇,我做错了。我实际上并不需要 oauth 模块。我需要请求模块来对 twitters api 进行简单的 GET 调用。

    // Setup the request object for OAuth Echo to twitter
    var options = {
      url: 'https://api.twitter.com/1.1/account/verify_credentials.json',
      headers: {
        'Authorization': req.headers['x-verify-credentials-authorization']
      }
    };
    
    // Make the request
    request(options, function (error, response, body) {
      if (!error && response.statusCode == 200) {
    
        // If twitter responds with a 200, the echo call was authorized
    
        // TODO: do stuff
    
        next();
      } else {
        res.send(401, 'Unauthorized');
        next();
      }
    });
    

    【讨论】:

    • 您能否使用 Chrome 上的 Postman 扩展程序发出该请求?
    • 我去过。对我来说,使用数字,端点是https://api.digits.com/1.1/sdk/account.json
    猜你喜欢
    • 2011-05-03
    • 1970-01-01
    • 2012-10-09
    • 2014-04-14
    • 1970-01-01
    • 2017-07-11
    • 2011-06-23
    • 2011-06-06
    • 1970-01-01
    相关资源
    最近更新 更多