I'm making an script to read data from google spreadsheet using the following script on nodejs:
我正在制作一个脚本,使用nodejs上的以下脚本从谷歌电子表格中读取数据:
var url = oauth2Client.generateAuthUrl({
access_type: 'offline',
approval_prompt: 'force',
scope: [
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/spreadsheets'
]
});
global.googleapis = { expiry_date: 0 };
google.options({ auth: oauth2Client });
var sheets = google.sheets('v4');
sheets.spreadsheets.get({ spreadsheetId: 'id'}, function(err, data) {
res.send(err, data);
});
But on every get request i'm getting this error:
但是在每次获取请求时我都会收到此错误:
Request had insufficient authentication scopes.
I checked the Google developers console to enable the Google Drive API and it's enabled, so I dont really know what could it be.
我检查了Google开发者控制台以启用Google Drive API并启用了它,所以我真的不知道它会是什么。
3 个解决方案
#1
17
The scopes look good, maybe you should try to remove the credentials stored previously in /Users/yourUserName/.credentials/sheets.googleapis.com-projectName/*
, and then execute the application again to get new credentials.
范围看起来不错,也许您应该尝试删除以前存储在/Users/yourUserName/.credentials/sheets.googleapis.com-projectName/*中的凭据,然后再次执行该应用程序以获取新凭据。
#2
12
-
Firstly delete the credentials files
~/.credentials/sheets.googleapis.com-nodejs-quickstart.json
(depending on your setting)首先删除凭证文件〜/ .credentials / sheets.googleapis.com-nodejs-quickstart.json(取决于您的设置)
-
Change the scope variable used for reading cells from Google Spreadsheets from
更改用于从Google Spreadsheets中读取单元格的范围变量
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
to
至
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
- After execution of code, API will authenticate again and then issue will be resolved.
- 执行代码后,API将再次进行身份验证,然后问题将得到解决。
#3
4
First, make sure you also enable the Sheets API in your Developers Console.
首先,请确保您还在Developers Console中启用了Sheets API。
The insufficient authentication scopes
is an error in the OAuth 2.0 token provided in the request specifies scopes that are insufficient for accessing the requested data.
认证范围不足是请求中提供的OAuth 2.0令牌中的错误,指定的范围不足以访问请求的数据。
So make sure you use the correct and all necessary scope and check this Authorizing requests with OAuth 2.0 if you properly follow the steps here.
因此,请确保使用正确且所有必要的范围,并且如果您正确执行此处的步骤,请使用OAuth 2.0检查此授权请求。
Lastly, try to revoke the access and try to redo it.
最后,尝试撤消访问权限并尝试重做它。
For more information, check this related SO question:
有关更多信息,请查看此相关的SO问题:
-
Write to GoogleSheet via API with Java
使用Java通过API写入GoogleSheet
-
Google Spreadsheets API with OAuth2.0 using Javascript
使用Javascript在OAuth2.0上使用Google Spreadsheets API
#1
17
The scopes look good, maybe you should try to remove the credentials stored previously in /Users/yourUserName/.credentials/sheets.googleapis.com-projectName/*
, and then execute the application again to get new credentials.
范围看起来不错,也许您应该尝试删除以前存储在/Users/yourUserName/.credentials/sheets.googleapis.com-projectName/*中的凭据,然后再次执行该应用程序以获取新凭据。
#2
12
-
Firstly delete the credentials files
~/.credentials/sheets.googleapis.com-nodejs-quickstart.json
(depending on your setting)首先删除凭证文件〜/ .credentials / sheets.googleapis.com-nodejs-quickstart.json(取决于您的设置)
-
Change the scope variable used for reading cells from Google Spreadsheets from
更改用于从Google Spreadsheets中读取单元格的范围变量
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
to
至
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
- After execution of code, API will authenticate again and then issue will be resolved.
- 执行代码后,API将再次进行身份验证,然后问题将得到解决。
#3
4
First, make sure you also enable the Sheets API in your Developers Console.
首先,请确保您还在Developers Console中启用了Sheets API。
The insufficient authentication scopes
is an error in the OAuth 2.0 token provided in the request specifies scopes that are insufficient for accessing the requested data.
认证范围不足是请求中提供的OAuth 2.0令牌中的错误,指定的范围不足以访问请求的数据。
So make sure you use the correct and all necessary scope and check this Authorizing requests with OAuth 2.0 if you properly follow the steps here.
因此,请确保使用正确且所有必要的范围,并且如果您正确执行此处的步骤,请使用OAuth 2.0检查此授权请求。
Lastly, try to revoke the access and try to redo it.
最后,尝试撤消访问权限并尝试重做它。
For more information, check this related SO question:
有关更多信息,请查看此相关的SO问题:
-
Write to GoogleSheet via API with Java
使用Java通过API写入GoogleSheet
-
Google Spreadsheets API with OAuth2.0 using Javascript
使用Javascript在OAuth2.0上使用Google Spreadsheets API