如何解决Google Drive API客户端Python:对filesinsert的权限不足
文件:insert需要具有以下至少一个作用域的授权
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/drive.filehttps://www.googleapis.com/auth/drive.appdatahttps://www.googleapis .com / auth / drive.apps.readonly
检查您要使用哪个范围进行身份验证。
解决方法
我正在尝试使一个简单的Python Google Drive上传器正常工作。我已经在开发人员控制台中创建了一个项目,启用了Drive
API,并添加了OAuth 2.0客户端ID(应用程序类型“其他”)。
我可以在Google云端硬盘的“设置”->“管理应用”中看到该应用程序,并且可以成功执行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')
任何人都可以指出我所缺少的权限吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。