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
相关产品推荐
相关产品推荐

