对Intrinio API的Meteor调用返回数据:null

时间:2017-04-07 18:39:09

标签: http meteor

有没有人有一个调用Intrinio财务数据API的例子?我正在尝试将their instructions与此Meteor Chef帖子进行调和,但只是在那里过了一半。我可以通过浏览器和命令行访问他们的数据,但不能通过我的代码。第一次使用任何类型的API,感谢任何建议。

另外,我知道有一个npm package for an Intrinio client。我在Meteor 1.2.1上,没有使用npm。

我添加了http包并在client / lib文件中写入以下内容:

getData = function() {
    HTTP.call('GET','api.intrinio.com', {
        query: "/companies?ticker=AAPL",
        authorization: "myUsername:myPassword"
        },
        function( error, response ) {
            if(error) {
                console.log("Error")    
            } else {
            console.log(response)
            }
        });
    };

在控制台中,返回以下内容 - 我获取了正确的状态代码,但数据为空:

Object {
    statusCode: 200,
    content: "<!DOCTYPE html>↵<html>↵<head>↵  <link rel="stylesh…pFinance</title>↵</head>↵<body>↵↵</body>↵</html>↵",
    headers: Object,
    data: null
}

Intrinio指令推荐以下内容,但这似乎与如何为Meteor编写调用的建议相冲突:

var https = require("https");

var username = ""username";
var password = ""password";
var auth = "Basic " + new Buffer(username + ':' + password).toString('base64');

var request = https.request({
    method: "GET",
    host: "api.intrinio.com",
    path: "/companies?ticker=AAPL",
    headers: {
        "Authorization": auth
    }
}, function(response) {
    var json = "";
    response.on('data', function (chunk) {
        json += chunk;
    });
    response.on('end', function() {
        var company = JSON.parse(json);
        console.log(company);
    });
});

request.end();

1 个答案:

答案 0 :(得分:1)

试试这个:

使用auth参数(而不是授权)

query参数必须仅包含查询字符串参数。 /公司需要成为URL的一部分。

为安全起见,请在URL中指定https://协议。

HTTP.call('GET','https://api.intrinio.com/companies', {
  query: "ticker=AAPL",
  auth: "myUsername:myPassword"
},
function( error, response ) {
  if (error) {
    console.log("Error", error)    
  } else {
    console.log(response)
  }
});

以下是上述代码的链接:https://github.com/intrinio/intrinio-meteor-example/blob/master/server/main.js

我希望这有帮助!顺便说一句,我为Intrinio工作。如果您将来需要,我们会提供免费的聊天支持。