Google Drive API Client(Python):文件权限不足().insert()

2024-05-17 10:11:54 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我可以看到Google Drive的设置中列出的应用程序->;管理应用程序,并可以成功执行来自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')

有人能告诉我我错过了什么许可吗?


Tags: apiidfalse应用程序httpservicegooglefiles
3条回答

正如@DalmTo所建议的,问题是在以下位置的范围不正确Auth

 flow_from_clientsecrets()

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

相关问题 更多 >