小编FGu*_*don的帖子

“无法设置未定义的属性‘jwtClient’”尝试在 Google 表格中使用 Node.js

我一直在关注本教程:https : //www.youtube.com/watch?v= UGN6EUi4Yio 由于这个问题,我不得不在 3:43 停止:

这是进入 Google 电子表格的主要 JS 文件:

const GoogleSpreadsheet = require('google-spreadsheet');
const { promisify } = require('util');
const { google } = require('googleapis');


const creds = require('./client_secret');

async function accessSpreadsheet()
{
    const doc = new GoogleSpreadsheet.GoogleSpreadsheet('1i1uSTZ5GkMJFqUGpxsvCOIOZJ6POPOuS9Vu0kDP1y_w');

    await promisify(doc.useServiceAccountAuth)(creds);
    const info = await promisify(doc.getInfo)();
    const sheet = info.worksheets[0];
    console.log(`TItle : ${sheet.title}, Rows: ${sheet.rowCount}`);
}

accessSpreadsheet();
Run Code Online (Sandbox Code Playgroud)

当我执行这个时,它给了我这个错误:

TypeError: Cannot set property 'jwtClient' of undefined
at useServiceAccountAuth (C:\Users\Web\WebstormProjects\discordjs\node_modules\google-spreadsheet\lib\GoogleSpreadsheet.js:53:20)"
Run Code Online (Sandbox Code Playgroud)

所以我去探索寻找功能。这是 GoogleSpreadsheet.js 和此代码块末尾的预期功能(该类的其余部分已删除):

const _ = require('lodash');
const { …
Run Code Online (Sandbox Code Playgroud)

javascript google-sheets node.js google-apps-script

7
推荐指数
1
解决办法
2489
查看次数