jto*_*srl 30 google-api node.js google-spreadsheet-api
我正在制作一个脚本,使用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);
});
Run Code Online (Sandbox Code Playgroud)
但是在每次获取请求时我都会收到此错误:
Request had insufficient authentication scopes.
Run Code Online (Sandbox Code Playgroud)
我检查了Google开发者控制台以启用Google Drive API并启用了它,所以我真的不知道它会是什么.
Lon*_*yen 44
首先删除凭证文件~/.credentials/sheets.googleapis.com-nodejs-quickstart.json
(取决于您的设置)
更改用于从Google Spreadsheets中读取单元格的范围变量
var SCOPES = [' https://www.googleapis.com/auth/spreadsheets.readonly '];
至
var SCOPES = [' https://www.googleapis.com/auth/spreadsheets '];
小智 20
范围看起来不错,也许您应该尝试删除先前存储的凭据/Users/yourUserName/.credentials/sheets.googleapis.com-projectName/*
,然后再次执行应用程序以获取新凭据.
小智 6
首先,请确保您还在开发人员控制台中启用了Sheets API。
的insufficient authentication scopes
是误差在OAuth 2.0令牌在所述请求指定提供范围是不够用于访问所请求的数据。
因此,请确保使用正确且所有必要的范围,如果您正确执行此处的步骤,请选中此OAuth 2.0授权请求。
最后,尝试撤消访问并尝试重做。
有关更多信息,请检查以下相关的SO问题: