Google Drive API客户端(Python):文件权限不足()。insert()

时间:2015-08-31 10:26:59

标签: oauth google-api google-drive-api google-oauth google-oauth2

我正在尝试使用简单的Python Google Drive上传器。我在开发者控制台中创建了一个项目,启用了Drive API并添加了OAuth 2.0客户端ID(应用程序类型为Other)。

我可以看到Google云端硬盘的设置中列出的应用 - >管理应用程序,并可以成功执行Google Drive Python API客户端提供的许多操作。然而,files()。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')

有人能指出我缺少哪些许可吗?

3 个答案:

答案 0 :(得分:19)

答案 1 :(得分:6)

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

答案 2 :(得分:1)

正如@DalmTo所建议的那样,问题是Auth范围不正确:

 flow_from_clientsecrets()