Google电子表格api请求的身份验证范围不足
我正在使用nodejs上的以下脚本编写脚本以从Google电子表格读取数据:
var url = oauth2Client.generateAuthUrl({
access_type: 'offline',
approval_prompt: 'force',
scope: [
'.readonly',
'',
''
]
});
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);
});
但是在每次获取请求时,我都会收到此错误:
Request had insufficient authentication scopes.
我检查了Google开发人员控制台以启用Google Drive API并启用了它,所以我真的不知道这可能是什么。
回答如下:- 首先删除凭据文件
~/.credentials/sheets.googleapis-nodejs-quickstart.json
(取决于您的设置)