如何更新 Google Drive API v3 中的权限?
How to update permissions in Google Drive API v3?
我使用服务帐户上传了 wav 文件,服务帐户创建了文件,服务帐户是所有者:
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
帐户的 role
从 writer
更改为 owner
并收到错误消息:
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
帐户时,它运行良好。
我尝试创建新权限并得到了这个:
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.)""
根据此处找到的文档Make someone else the owner of your file
From your personal account, you can transfer the following file types:
- 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 驱动器不支持传输该文件类型,则服务帐户也无法传输它。
解决方法。让用户将文件上传到他们的帐户而不是服务帐户。
我使用服务帐户上传了 wav 文件,服务帐户创建了文件,服务帐户是所有者:
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
帐户的 role
从 writer
更改为 owner
并收到错误消息:
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
帐户时,它运行良好。
我尝试创建新权限并得到了这个:
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.)""
根据此处找到的文档Make someone else the owner of your file
From your personal account, you can transfer the following file types:
- 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 驱动器不支持传输该文件类型,则服务帐户也无法传输它。
解决方法。让用户将文件上传到他们的帐户而不是服务帐户。