【发布时间】:2016-06-15 07:56:12
【问题描述】:
我已设法授予用户访问权限,从而根据需要将access_token 获取到retrieve the data from the Angellist API。
下一步是获取用户数据。正如我们可以从 Angellist API 中看到的那样,您可以通过经过身份验证的 HTTPS GET 请求来做到这一点:
使用令牌
必须进行任何需要身份验证的请求 使用 HTTPS,使用 HTTP 授权中提供的访问令牌 标头、请求正文或查询字符串。 AngelList 只支持 Bearer 令牌,定义在 https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-bearer-08。一个例子 使用查询字符串:
GET https://api.angel.co/1/me?
access_token=...
为了在 NodeJS 中发出请求,我使用 npm 包 request 如下:
function testRequest(access_token) {
console.log('test request');
var urltest = "https://api.angel.co/1/me?access_token=" + access_token;
request.get(urltest,
{
'auth': {
'bearer': access_token
}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log('body', body)
}
console.log('body', body)
console.log('error', error)
}
);
};
但是,我不断收到错误消息:
body {"success":false,"error":{"type":"unauthorized","message":"The authenticated user is not authorized for this request."}}
我做错了什么? access_token 是否需要转换或其他什么,即它不是不记名令牌?
【问题讨论】:
-
你有没有尝试在邮递员或其他客户端中使用该api?
-
当我通过 url 发送请求时返回相同的错误。不确定如何使用 Postman 添加不记名令牌?
-
好的,我在 Postman 中添加了一个标头:Authorization with value "Bearer 12345token",它返回了同样的错误。
标签: node.js oauth https httprequest bearer-token