Google Drive API Client (Python): Insufficient Permission fo



我试图得到一个简单的Python谷歌驱动器上传工作。我已经在开发者控制台中创建了一个项目,启用了Drive API并添加了OAuth 2.0客户端ID(应用程序类型Other)。

我可以看到在Google Drive的Settings -> Manage Apps中列出的应用程序,并且可以成功地执行许多由Google提供的Python Drive API客户端提供的操作。文件()。然而,Insert()在使用

时失败
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=false&useContentAsIndexableText=false&alt=json returned "Insufficient Permission">

这是一个插入目录的命令,我把它设置为每个人都可以写,如下所示:

credentials = get_credentials ()
http = credentials.authorize (httplib2.Http ())
service = discovery.build ('drive', 'v2', http=http)
PARENT_ID="0B1gLgXwTiUzlfmo0UGVsZ1NWdW1nZG9OcENNYkJua2E1d0pqWE14TjFyc2hVMHdEU1h5czQ"
perms = service.permissions().list(fileId=PARENT_ID).execute()
print ("PERMISSIONS:")
for perm in perms["items"]:
    for p in perm:
        print (p, perm[p])
print
parent = {
    "isRoot": False,
    "kind": "drive#parentReference",
    "id": PARENT_ID
}
service.files ().insert (
    body = {"parents" : [parent]},
    media_body='./test.txt',
    convert=False,
    useContentAsIndexableText=False
).execute ()

将权限列出为:

(u'withLink', True)
(u'kind', u'drive#permission')
(u'etag', u'"F-w0rsCIWtQP8RGyv_V1DlKfcRk/icwHkDdfUYuMzqZrUsVIyvu85K8"')
(u'role', u'writer')
(u'type', u'anyone')
(u'id', u'anyoneWithLink')
(u'selfLink', u'https://www.googleapis.com/drive/v2/files/0B1gLgXwTiUzlfmo0UGVsZ1NWdW1nZG9OcENNYkJua2E1d0pqWE14TjFyc2hVMHdEU1h5czQ/permissions/anyoneWithLink')

谁能告诉我我少了哪个许可?

Files: insert要求至少具有以下作用域之一的授权

https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.apps.readonly

如果修改这些范围或权限,请尝试删除以前保存的凭证相关文件或浏览器缓存(如果有)。

根据@DalmTo的建议,问题是Auth范围不正确:

 flow_from_clientsecrets()

最新更新