使用NodeJS和Request的AngelList API进行简单的HTTPS GET [英] Simple HTTPS GET from the AngelList API with NodeJS and Request

查看:200
本文介绍了使用NodeJS和Request的AngelList API进行简单的HTTPS GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法授予用户访问权限,从而根据需要获取<$ href =https://angel.co/api/oauth access_token / faqrel =nofollow>从Angellist API中检索数据。

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.

下一步是获取用户数据。我们可以从Angellist API中读取,您可以通过经过身份验证的HTTPS GET请求来执行此操作:

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:


使用令牌

任何需要身份验证的请求必须使用HTTPS进行
,并在HTTP Authorization
标头,请求正文或查询字符串中提供访问令牌。 AngelList仅支持Bearer
令牌,如
中所定义 http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-08 。使用查询字符串的示例

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=...

要在NodeJS中发出请求,我使用npm包请求如下:

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."}}

我做错了什么? access_token是否需要转换或者其他东西,即它不是持票人令牌?

What am I doing wrong? Does the access_token need to be converted or something, i.e. it is not a bearer token?

推荐答案

我在尝试时发现使用另一个AngelList帐户登录,然后就可以了。我之前尝试过的帐户与我注册客户端应用程序的帐户相同。不知道为什么这会有所作为,但它确实有效。

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.

这篇关于使用NodeJS和Request的AngelList API进行简单的HTTPS GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆