我正在使用googleapis库v44.0.0。尝试登录时,出现错误。
之前在项目33120758中未使用过Google Sheets API或已将其禁用。通过访问https://console.developers.google.com/apis/api/sheets.googleapis.com/overview?project=33120758启用它,然后重试。如果您最近启用了此API,请等待几分钟,以便该操作传播到我们的系统并重试。
我在同一项目上使用google-auth-library版本^ 0.10.0。而且不是这个错误。
const { google } = require("googleapis");
// ...
const JwtClient = new google.auth.JWT(
client_email,
null,
private_key,
["https://www.googleapis.com/auth/spreadsheets"]
);
await JwtClient.authorize();
google.options({ auth: JwtClient });
// ...
const client = google.sheets({ version: "v4" });
const data = await client.spreadsheets.get({ spreadsheetId: myId});
答案 0 :(得分:1)
如果我的理解是正确的,那么该修改如何?
await JwtClient.authorize();
google.options({ auth: JwtClient });
// ...
const client = google.sheets({ version: "v4" });
const data = await client.spreadsheets.get({ spreadsheetId: myId});
至:
const client = google.sheets({ version: "v4", "auth": JwtClient });
const data = await client.spreadsheets.get({ spreadsheetId: myId});
console.log(data.data)
在我的环境中,我可以确认修改后的脚本有效。但是,如果这不能解决您的问题,我深表歉意。