Ful*_*xel 4 javascript node.js meteor
需要连接到外部api:Vogogo.困难的部分是将curl示例转换为有效的Meteor HTTP.get调用.现在这是我提出的代码
apiversionVogogo = 'v3';
Vogogo.listAllCustomers = function() {
HTTP.get('https://api.vogogo.com/' + apiversionVogogo + '/customers', {
headers: {
'Authorization': {
user: clientID,
clientsecret: apisecret
}
}
},
function(error, result) {
if (error) {
console.log(error);
} else {
console.log(result);
}
});
return;
}
Run Code Online (Sandbox Code Playgroud)
响应是一条错误消息:
error_message: 'HTTP Authorization expected"'
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我将这个基本的HTTP身份验证重写为默认格式吗?在文档中,使用CURL给出了一个示例.
curl -X GET 'https://api.vogogo.com/v3/customers' \
--user clientsecret: \
-H "Content-Type: application/json"
Run Code Online (Sandbox Code Playgroud)
Nat*_*ate 10
使用auth选项字段中的参数,而不是在标题中实际设置授权.来自Docs : auth String HTTP basic authentication string of the form "username:password". 您的要求如下:
HTTP.get('https://api.vogogo.com/' + apiversionVogogo + '/customers', { auth : "clientID:apisecret"})
Run Code Online (Sandbox Code Playgroud)