typescript - 工作表 API (google apis) 返回错误“'无效授权:找不到帐户'
问题描述
我想通过 sheet api 从电子表格中获取数据。
我在 GCP 和服务帐户中创建项目。然后我授予该帐户编写电子表格的权限。之后,我将凭据下载为 json。
我的node应用在这里。
const sheets = google.sheets('v4');
execAPI('[sheet_ID]', 'articles!C5:F8');
async function execAPI(spreadsheetId: string, range: string) {
const key = process.env.private_key === undefined ? undefined : process.env.private_key.replace(/\\n/g, "\n");
const auth = await google.auth.getClient({
credentials: {
client_email: process.env.client_email,
private_key: key,
},
scopes: 'https://www.googleapis.com/auth/spreadsheets.readonly',
});
const apiOptions = {
auth,
spreadsheetId,
range,
};
sheets.spreadsheets.values.get(apiOptions, (err: Error | null, res: GaxiosResponse | undefined | null) => {
console.log(err);
console.log(res);
});
但是,我尝试了很多次,但只收到错误“无效授权:找不到帐户”
我应该怎么办??请教我。
解决方案
此错误表示授权授予或刷新令牌无效
发生这种情况的原因有多种 - 请参见此处,最有可能是您更改了范围:这样做之后,您需要删除旧令牌文件,以便应用程序创建一个新的更新令牌。
推荐阅读
- javascript - JS- 相应地过滤 JSON
- javascript - evoPDF 转换触发模式不起作用
- image - 在我在 vue chrome 开发工具中打开组件之前,数据属性中的图像文件路径不会显示
- charts - 如何用 highcharts 库绘制欧拉图?
- eclipse - 如何将现有的 iLog 规则 jar 导入 Eclipse?
- azure - 如何使用 azure 将数据加载到 sql sink 中?
- swift - UIPickerView 在重新加载时冻结 UI
- node.js - 避免工作负载与并行服务重叠
- javascript - React build issus:你可能需要一个合适的加载器来处理这个文件类型,目前没有配置加载器来处理这个文件
- javascript - ES5 中的可共享组件