Google 电子表格 api 请求的身份验证范围不足 [英] Google spreadsheet api Request had insufficient authentication scopes

查看:24
本文介绍了Google 电子表格 api 请求的身份验证范围不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来使用 nodejs 上的以下脚本从谷歌电子表格中读取数据:

var url = oauth2Client.generateAuthUrl({access_type: '离线',批准提示:'强制',范围: ['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 sheet = google.sheets('v4');sheet.spreadsheets.get({电子表格ID:'id'},函数(错误,数据){res.send(错误,数据);});

但是在每次获取请求时,我都会收到此错误:

请求的身份验证范围不足.

我检查了 Google 开发者控制台以启用 Google Drive API 并且它已启用,所以我真的不知道它会是什么.

解决方案

  1. 首先删除凭证文件~/.credentials/sheets.googleapis.com-nodejs-quickstart.json(取决于你的设置)

  2. 更改用于从 Google 电子表格中读取单元格的范围变量

<块引用>

变量范围=['https://www.googleapis.com/auth/spreadsheets.readonly'];

<块引用>

var SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];

  1. 执行代码后,API 将再次进行身份验证,然后问题将得到解决.

I'm making an script to read data from google spreadsheet using the following script on 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.

解决方案

  1. Firstly delete the credentials files ~/.credentials/sheets.googleapis.com-nodejs-quickstart.json (depending on your setting)

  2. Change the scope variable used for reading cells from Google Spreadsheets from

var SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];

to

var SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];

  1. After the execution of code, API will authenticate again and then the issue will be resolved.

这篇关于Google 电子表格 api 请求的身份验证范围不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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