Google Drive API Client(Python):文件权限不足()。insert() [英] Google Drive API Client (Python): Insufficient Permission for files().insert()

查看:227
本文介绍了Google Drive API Client(Python):文件权限不足()。insert()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得一个简单的Python Google Drive上传工作。我在开发人员控制台中创建了一个项目,启用了Drive API并添加了OAuth 2.0客户端ID(应用程序类型为Other)。

I am trying to get a simple Python Google Drive uploader working. I've created a project in the developer console, enabled the Drive API and added an OAuth 2.0 client ID (application type Other).

我可以看到列出的应用程序Google云端硬盘的设置 - >管理应用,并且可以成功执行Google的Python Drive API客户端提供的许多操作。然而,文件().insert()却失败:

I can see the application listed in the Google Drive's Settings -> Manage Apps, and can successfully execute many operations provided by the Python Drive API client from Google. files ().insert () however fails with:

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">

这是为了插入到一个我已经写入所有人的目录中,如下所示:

This is for an insert into a directory which I have made writable to everyone, as seen below:

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 ()

其中列出权限:

Which lists the permission as:

(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')

任何人都可以指出我缺少的权限吗?

Can anyone point me to which permission I am missing, please?

推荐答案

文件:insert 需要至少一个以下范围的授权

Files: insert requires authorization with at least one of the following scopes

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

检查哪个范围您正在使用。

Check which scope you are authenticating with.

这篇关于Google Drive API Client(Python):文件权限不足()。insert()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆