You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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));

额外检查项

  1. 确认你的API Key在Google Cloud控制台已经启用了Google Sheets API,没启用的话去API库搜索开启即可。
  2. 目标表格的共享权限要设置成允许公开访问(比如“任何人拥有链接即可查看”),否则即使密钥正确也会被拒绝。

内容的提问来源于stack exchange,提问作者Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 02:55:59