lam*_*ams 9 google-api node.js google-drive-api google-cloud-platform
我正在尝试根据以下代码访问电子表格中的信息,但出现此错误,我不太明白其原因。
我已经在谷歌上授予了凭据电子邮件的许可...
const { google } = require("googleapis");
const creds = require("./config/gCredentials.json");
const client = new google.auth.JWT(
creds.client_email,
null,
creds.private_key,
["https://www.googleapis.com/auth/spreadsheets"]
);
client.authorize(function (err, tokens) {
if (err) {
console.log(err);
} else {
console.log("connected");
gsrun(client);
}
});
async function gsrun(cl) {
const gsapi = google.sheets({ version: "v4", auth: cl });
const opt = {
spreadsheetId: "XYZ",
range: "SheetA!A1:B14",
};
let data = await gsapi.spreadsheets.values.get(opt);
console.log(data);
}
Run Code Online (Sandbox Code Playgroud)
知道它可能是什么吗?
错误控制台
connected
(node:31301) UnhandledPromiseRejectionWarning: Error: This operation is not supported for this document
at Gaxios.<anonymous> (****/node_modules/googleapis/node_modules/gaxios/build/src/gaxios.js:73:27)
at Generator.next (<anonymous>)
at fulfilled (****/node_modules/googleapis/node_modules/gaxios/build/src/gaxios.js:16:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:31301) 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:31301) [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.
Run Code Online (Sandbox Code Playgroud)
lam*_*ams 20
我能够确定问题所在。代码是正确的,但是,谷歌驱动器上的文件被保存为 xlsx 而不是谷歌电子表格......
我通过转到“文件”>“另存为 Google 表格”来转换电子表格。
谢谢