我试图让一个不和谐的机器人访问谷歌电子表格,但这个错误不断出现,我无法解决它,我按照这个视频(https://www.youtube.com/watch?v=UGN6EUi4Yio),并做了一切,直到程序运行的点。有什么办法解决这个问题吗?先谢谢你了。
UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'jwtClient' of undefined
at useServiceAccountAuth (Z:\GitHub\discordBot\node_modules\google-spreadsheet\lib\GoogleSpreadsheet.js:60:20)
at internal/util.js:297:30
at new Promise (<anonymous>)
at useServiceAccountAuth (internal/util.js:296:12)
at accessSpreadsheet (Z:\GitHub\discordBot\sheets\sheets.js:8:45)
at Object.module.exports.run (Z:\GitHub\discordBot\comandos\duvida.js:51:5)
at Client.<anonymous> (Z:\GitHub\discordBot\index.js:63:21)
at Client.emit (events.js:311:20)
at MessageCreateHandler.handle (Z:\GitHub\discordBot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (Z:\GitHub\discordBot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
字符串
我的sheets.js文件:
const { GoogleSpreadsheet } = require('google-spreadsheet');
const { promisify } = require('util');
const creds = require('./client_secret.json');
async function accessSpreadsheet(){
const doc = new GoogleSpreadsheet('1klBj2ZSk-IaDAT-w8kUKzmLw-o5oAk9otZL6xh1vnks');
await promisify(doc.useServiceAccountAuth)(creds);
const info = await promisify(doc.getInfo)();
const sheet = info.worksheets[0];
console.log(`Title: ${sheet.title}`);
}
module.exports.accessSpreadsheet = accessSpreadsheet;
型
1条答案
按热度按时间0h4hbjxa1#
以下是我的理解:
google-spreadsheet
模块检索电子表格中第一个选项卡的标题。client_secret.json
是服务帐户的凭据文件。如果您使用的是最新版本的
google-spreadsheet
(现阶段是google-spreadsheet@3.0.10
.),那么进行以下修改如何?修改脚本:
字符串
注意:
client_secret.json
不用于服务帐户时,将出现No key or keyFile set
错误。请小心这个。The caller does not have permission
错误时,请将电子表格与服务帐户的电子邮件共享。参考: