python - Google Drive API 客户端 (Python) : Insufficient Permission for files(). insert()

标签 python oauth google-api google-drive-api google-oauth

我正在尝试让一个简单的 Python Google Drive uploader 正常工作。我已在开发者控制台中创建了一个项目,启用了 Drive API 并添加了 OAuth 2.0 客户端 ID(应用程序类型“其他”)。

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

有人可以指出我缺少哪个权限吗?

最佳答案

关于python - Google Drive API 客户端 (Python) : Insufficient Permission for files(). insert(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32309136/

相关文章:

python - 如何在没有 python oauth2client lib 的情况下实现谷歌登录混合服务器端流程

google-api - 环聊应用的 http 请求被阻止

python - SQLite 中字符串文字和标识符的区别

python - 是否可以将 python gdb 变量捕获到值历史记录中?

IOS Google OAuth 1 次认证成功后出现错误

api - 使用 OAuth...我不明白。我应该做些什么?

javascript - Google oauth 中的 session 处理

google-api - 如何找出哪些列组合在adwords中有效

python - 借用 Python API ; websocket 仅返回 1 条有效消息

python : optional arguments for function calling lower level functions