新手试图找出如何让 Node.js 应用程序来验证和查询 Google BigQuery,试图适应 this CodeLab tutorial from Java 。我可能缺少哪一步?
首先,我使用我的 clientid 创建此 Oauth2 URL:
https://accounts.google.com/o/oauth2/auth?
client_id=1047877053699-den6kbs4v3f2bft6clonsirkj1pc7t6j.apps.googleusercontent.com
&scope=https://www.googleapis.com/auth/bigquery
&redirect_uri=http://localhost:3000/oauth2callback
&access_type=offline
&response_type=code
这已成功到达 Google,并出现提示
A third party service is requesting permission to access your Google Account.
同意生成第二个提示:
Nodejs_Test is requesting permission to: View and manage your data in Google BigQuery
同意这一点,将使用参数 accessToken
调用回调 URL。
我认为以下网址应列出我的 BigQuery 项目/数据集中的表:
但是使用或不使用 accessToken 进行调用都会返回以下消息:“需要登录”。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
我知道由于权限、过期 token 等原因,您无法重复代码。但我想知道我在概念上可能缺少哪一步。
最佳答案
您是否尝试过将 accesstoken 作为授权 header 而不是作为 url 参数发送?
如
https://www.googleapis.com/bigquery/v2/projects/1047877053699/datasets/visits
Authorization: OAuth Your-access-token-here-not-urlencoded
关于node.js - 通过 OAuth2 从 Node.js 向 BigQuery REST API 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11989001/