使用JavaScript调用Google Sheets API批量读取时触发403权限错误
Google Sheets values.getBatch 403权限错误解决办法
问题根源
你写的批量请求URL里,API Key的参数连接符号错了——应该用&而不是?。URL规则里,只有第一个查询参数用?开头,后面所有参数都得用&拼接。这个错误导致API没识别到你的密钥,直接返回了权限拒绝。
修正后的代码
const apiKey = 'key-here'; const spreadsheetId = 'sheet-id-here'; fetch(`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values:batchGet?ranges=Sheet1!A1:A2&ranges=subtitle!B1:B2&key=${apiKey}`) .then(response => response.json()) .then(data => console.dir(data)) .catch(error => console.error('Google Sheet Reading Error: ', error));
额外检查项
- 确认你的API Key在Google Cloud控制台已经启用了Google Sheets API,没启用的话去API库搜索开启即可。
- 目标表格的共享权限要设置成允许公开访问(比如“任何人拥有链接即可查看”),否则即使密钥正确也会被拒绝。
内容的提问来源于stack exchange,提问作者Kim
相关产品推荐
相关产品推荐

