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

使用Python API和ADC读取谷歌表格遇403权限不足问题排查

Google Sheets API 403权限问题

我编写了以下代码:

scope = ['https://www.googleapis.com/auth/cloud-platform',
         'https://www.googleapis.com/auth/drive',
         'https://www.googleapis.com/auth/spreadsheets',
         'https://www.googleapis.com/auth/spreadsheets.readonly']

credentials, project = google.auth.default(scopes=scope)

service = discovery.build('sheets', 'v4', credentials=credentials, cache_discovery=False)
sheet = service.spreadsheets()
result_input = sheet.values().get(spreadsheetId=id,range=range).execute()

但即便表格已设为公开,我仍收到403错误:

googleapiclient.errors.HttpError: <HttpError 403 when requesting
https://sheets.googleapis.com/v4/spreadsheets/<SHEET_ID_HERE>/values/<RANGE_HERE>?alt=json returned "Request had insufficient authentication scopes.". Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', 'domain': 'googleapis.com', 'metadata': {'service': 'sheets.googleapis.com', 'method': 'google.apps.sheets.v4.SpreadsheetsService.GetValues'}}]">

已完成以下配置:

  • Google SDK配置正常
  • 我是该GCP项目的所有者
  • 我是该谷歌表格的所有者,且邮箱一致(表格已设为公开)

我不想下载任何.json格式的API密钥,是否有其他解决方案?我哪里操作出错了?

补充说明
似乎无法使用ADC(应用默认凭据)访问Google Sheets API,必须通过服务账号或Oauth2配置实现。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 07:45:38