问题
I have managed to grant access from the user, thus to get the access_token
as needed to retrieve the data from the Angellist API.
The next step is to fetch the user data. As we can read from the Angellist API, you do this by authenticated HTTPS GET requests:
Use the Token
Any requests that require authentication must be made using HTTPS, with the access token provided in the HTTP Authorization header, request body or query string. AngelList only supports Bearer tokens, as defined in http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-08. An example using the query string:
GET https://api.angel.co/1/me?
access_token=...
To make the request in NodeJS, I use the npm package request as follows:
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)
}
);
};
However, I keep getting the error:
body {"success":false,"error":{"type":"unauthorized","message":"The authenticated user is not authorized for this request."}}
What am I doing wrong? Does the access_token need to be converted or something, i.e. it is not a bearer token?
回答1:
Can you try to send the request as follows:
var optionsGetUserInfo = {
method: 'GET',
url: "https://api.angel.co/1/me?access_token=" + access_token",
headers: {
'Authorization': 'Bearer ' + access_token
'Accept' : 'application/json',
'Content-Type' : 'application/json'
}
}
request(optionsGetUserInfo, function (error, response, body) {
if (!error && response.statusCode == 200) {
etc...
回答2:
I have found out that when trying to sign in with another AngelList account, then it works. The account that I tried before was the same as on which I had registered the client app. Not sure why this makes a difference, but it works.
来源:https://stackoverflow.com/questions/35747640/simple-https-get-from-the-angellist-api-with-nodejs-and-request