You need to enable JavaScript to run this app. Google Drive API V3使用drive.appdata scope列文件出现权限不足问题
优惠活动
大模型
产品
解决方案
定价
更多

Google Drive API V3使用drive.appdata scope列文件出现权限不足问题

问题原因

drive.appdata 权限仅允许访问Google Drive中专属的应用数据存储空间 appDataFolder,而files.list接口默认查询的是普通用户Drive空间(drive空间),权限不匹配就会触发你收到的The granted scopes do not give access to all of the requested spaces.报错。

修复方案

调用files.list时显式指定spaces参数为appDataFolder即可,修改后的代码如下:

response = self.service.files().list(
    q="name = 'test.txt'",
    spaces='appDataFolder'
).execute()
补充说明
  • 如果同时需要查询多个空间,需要确认你申请的权限覆盖对应空间,比如同时申请drive和drive.appdata权限后,spaces参数可以填drive,appDataFolder
  • appDataFolder中的文件仅你的应用可访问,用户也无法在普通Drive界面中查看这些文件,适合存储应用配置、缓存等私有数据

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.20 14:24:03