如何在Google Drive API v3中更新权限? [英] How to update permissions in Google Drive API v3?

查看:103
本文介绍了如何在Google Drive API v3中更新权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用服务帐户上传了wav文件,服务帐户创建了文件,服务帐户是所有者:

I uploaded wav file using service account, service account created the file, service account is the owner:

metadata = {'name': filename, 'parents': [FolderId]}
media = MediaFileUpload(filepath, mimetype='audio/wav')
r = drive.files().create(body=metadata, media_body=media, fields='id').execute()

{'permissions': [{'deleted': False,
              'displayName': 'My name',
              'emailAddress': 'myemail@gmail.com',
              'id': '00654354190098938408',
              'kind': 'drive#permission',
              'photoLink': 'https://lh6.googleusercontent.com/photo.jpg',
              'role': 'writer',
              'type': 'user'},
             {'deleted': False,
              'displayName': 'myservice@myservice.iam.gserviceaccount.com',
              'emailAddress': 'myservice@myservice.iam.gserviceaccount.com',
              'id': '16815597635264162472',
              'kind': 'drive#permission',
              'role': 'owner',
              'type': 'user'}]}

然后我正尝试将myemail帐户的rolewriter更改为owner并得到一个错误:

Then I'm trying to change the role of myemail account from writer to owner and get an error:

drive.permissions().update(fileId=fileId, permissionId='00654354190098938408', transferOwnership=True,
    body={'role': 'owner'}).execute()

用户对此文件没有足够的权限.

The user does not have sufficient permissions for this file.

怎么了?

我的服务帐户是所有者,我可以通过该服务帐户删除文件,但它没有转让所有权的权限,为什么? 当我使用service帐户创建电子表格并将所有权转让给myemail帐户时,它可以正常工作.

My service account is the owner, I CAN delete the file through the service account and it does not have permissions to transfer ownership, why? When I create a spreadsheet with service account and transfer ownership to myemail account it works perfectly.

我试图创建新权限并获得了此权限:

I tried to create new permission and got this:

permission = {
    "emailAddress": 'myemail@gmail.com',
    "role": 'owner',
    "type": 'user',
}
drive.permissions().create(fileId=fileId, body=permission, transferOwnership=True).execute()

"错误请求.用户消息:您尚无法更改此项目的所有者. (我们正在努力.)"

"Bad Request. User message: "You can't yet change the owner of this item. (We're working on it.)""

推荐答案

根据此处找到的文档让其他人成为您文件的所有者

通过您的个人帐户,您可以传输以下文件类型:

From your personal account, you can transfer the following file types:

  • Google文档
  • Google表格
  • Google幻灯片
  • Google表单
  • Google绘图
  • Google我的地图
  • 文件夹 提示:转让文件夹的所有权时,它只会转让选定的文件夹,而不会在其中包括文件.
  • Google Docs
  • Google Sheets
  • Google Slides
  • Google Forms
  • Google Drawings
  • Google My Maps
  • Folders Tip: When you transfer ownership of a folder it transfers only the selected folder and does not include the files inside.

如果google驱动器不支持传输该文件类型,则该服务帐户也将无法传输该文件类型.

If google drive doesn't support transferring that file type then the service account isnt going to be able to transfer it either.

解决方法.让用户将文件上传到他们的帐户而不是服务帐户.

Workaround. Have the user upload the file to their account and not the service account.

这篇关于如何在Google Drive API v3中更新权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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