【问题标题】:Mavenlink API with node带有节点的 Mavenlink API
【发布时间】:2016-03-02 04:57:04
【问题描述】:

我正在尝试使用节点连接到 mavenlink,但我不断收到 oauth2 验证错误。每个在线解决方案都与许多用户的令牌生成有关,但我只需要操作数据以在内部应用程序中使用。有人有一个用户的 oauth2 身份验证示例吗?

【问题讨论】:

    标签: node.js oauth-2.0


    【解决方案1】:

    在这种情况下,oauth2 身份验证是通过 headers 选项中的"Authorization": "Bearer key".toString('base64') 实现的。

    var https = require("https");
    
    function printError (error) {
        console.error(error);
    }
    
    key = 'oauth2 token';
    var options = {
      host: 'api.mavenlink.com',
      path: '/api/v1/workspaces.json',
      method: 'GET',
      headers: {
            "Content-type": "application/json",
            "Authorization": "Bearer key".toString('base64')
          }
    };
    
    var body = "";
    
    var req = https.request(options, (res) => {
      console.log('statusCode: ', res.statusCode);
      console.log('headers: ', res.headers);
    
      res.on('data', (d) => {
        process.stdout.write(d);
    
      });
    
      res.on('data', function (chunks){
        body += chunks;
      });
    
      res.on('end', function() {
        if(res.statusCode == 200) {
          try
          {
            //parse data
            var massData = JSON.parse(body);
            console.log(body);
          } catch(error) {
            //parse error
            printError(error);
          }
        }
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2018-01-20
      • 2017-10-03
      • 2015-03-09
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 2014-06-07
      相关资源
      最近更新 更多