我正在制作一个脚本,在nodejs上使用以下脚本从谷歌Electron 表格读取数据:

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);
});

但每次get请求我都会遇到这样的错误:

Request had insufficient authentication scopes.

我判断了Google开发者控制台以启用Google Drive API,它已经启用,所以我不知道它可能是什么.

推荐答案

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

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

变量范围=

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

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

Node.js相关问答推荐

使用prisma迁移到SQL失败

使用HTTPS从NodeJS 17.9.1升级到18.0.0后,SignalR连接失败

即使DDB键不存在, node Lambda也不会失败,并返回NULL作为结果

编辑Mongoose中的对象嵌套数组

根据我的测试,为什么在编写Varint代码方面,NodeJS要比Rust快这么多?

如果我在父文件夹中运行,子进程生成不起作用

2023年如何在Node.js中使用Gmail发送邮箱?

与诗乃一起嘲笑奈克斯

Typescript :泛型类又扩展了另一个泛型类

在对象数组中的数组中嵌套 $lookup - Mongodb

为什么 nginx 不将我的 react index.html 作为后备服务

如何修改这个flake.nix,这样我就不用每次加载环境都加载nix包了

Fly.io 启动问题:无法从源获取图像或构建错误:构建错误:连接期间出错:发布...

firebase/messaging 不提供名为 getToken 的导出

使用react 组件加载特定 DIV 而无需重新加载整个页面

如何解决这个关于 TaskRunner 的 Node/Express 代码问题?

如何解决 npm install react-select failure with error : An unknown git error occurred, git@github.com :Permission denied (publickey)

更新文档数组中的文档 Mongoose

如何在 mongoDB 中用值 0 填充缺失的文档?

node.js 示例