Powershell выдает сообщение об ошибке при выполнении кода node.js, ожидающего изменения в электронной таблице - PullRequest
0 голосов
/ 09 апреля 2020
function checkForChanges() {
    let spreadsheetId = '1oHNELBZ3zV4PQBVsJrtqX4Cz00IFmJG_2SaJ4bgTa3c'
    let ranges = ['A2:P2', 'A3:P3', 'A4:P4', 'A5:P5']
    this.batchGet ({
        spreadsheetId,
        ranges, 
        }, (err, result) => {
            if (err) {
                console.log(err);
            } else {
                console.log(`${result.valueRanges.length} ranges retrieved.`);
            } 

    })
}

client.on('ready', () => {
    while (true) {
        checkForChanges();
    }
});

Я ожидаю, что когда я что-то изменю в электронной таблице, она вернется в консоль с тем, что было изменено. но вместо этого я получаю эту ошибку при запуске программы:

[nodemon] starting `node --inspect turnip_bot.js`
Debugger listening on ws://127.0.0.1:9229/b52c6ec8-70cb-451a-9b70-fc8bada920fc
For help, see: https://nodejs.org/en/docs/inspector
(node:1200) UnhandledPromiseRejectionWarning: TypeError: this.batchGet is not a function
    at checkForChanges (D:\Programing\Node.js\Discord-Turnip-Bot\turnip_bot.js:72:7)
    at Client.<anonymous> (D:\Programing\Node.js\Discord-Turnip-Bot\turnip_bot.js:87:3)
    at Client.emit (events.js:323:22)
    at WebSocketManager.triggerClientReady (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:433:17)
    at WebSocketManager.checkShardsReady (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:417:10)
    at WebSocketShard.<anonymous> (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:199:14)
    at WebSocketShard.emit (events.js:311:20)
    at WebSocketShard.checkReady (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:466:12)
    at WebSocketShard.onPacket (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:438:16)
    at WebSocketShard.onMessage (D:\Programing\Node.js\Discord-Turnip-Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
(node:1200) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1200) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Я взял код из быстрого запуска API листов Google и немного отредактировал его для своего случая использования, а также использовал некоторую документацию, чтобы помочь с чтением электронная таблица с несколькими строками.

Если запустить образец, он вернет:

[nodemon] starting `node --inspect google_sheets_api_sample.js`
Debugger listening on ws://127.0.0.1:9229/04ef1aed-3c10-40e5-b8f2-78782b5537bc
For help, see: https://nodejs.org/en/docs/inspector
(node:3208) UnhandledPromiseRejectionWarning: Error: authentication failed
    at authorize (D:\Programing\Node.js\Discord-Turnip-Bot\google_sheets_api_sample.js:57:11)
    at main (D:\Programing\Node.js\Discord-Turnip-Bot\google_sheets_api_sample.js:13:28)
    at Object.<anonymous> (D:\Programing\Node.js\Discord-Turnip-Bot\google_sheets_api_sample.js:42:1)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
(node:3208) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3208) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[nodemon] clean exit - waiting for changes before restart
...