drive_service = discovery.build('drive', 'v3', credentials=credentials) # Use "credentials" of "gspread.authorize(credentials)".
folderId = "###" # Please set the folder ID.
permission = {
'type': 'user',
'role': 'writer',
'emailAddress': '###', # Please set the email address of the user that you want to share.
}
res = drive_service.permissions().create(fileId=folderId, body=permission).execute()
print(res)
如果我的理解是正确的,这个答案呢?在
修改点:
gspread.authorize()
,就像gc = gspread.authorize(credentials)
。在这个修改中,credentials
被使用。在准备工作:
在使用以下脚本之前,请在API控制台启用驱动器API,并添加
https://www.googleapis.com/auth/drive
的作用域。如果您正在使用https://www.googleapis.com/auth/drive.file
的作用域,请使用它,并且不需要将该作用域修改为https://www.googleapis.com/auth/drive
。在如果您使用的是OAuth2,请删除包含刷新令牌的文件。然后,请运行脚本并重新授权。这样,添加的作用域将反映到访问令牌。
如果您使用的是服务帐户,则不需要删除该文件。
模式1:
下面的示例脚本将为特定文件夹创建新的电子表格。在
示例脚本:
模式2:
如果要将现有电子表格移动到特定文件夹,请使用以下脚本。在
示例脚本:
^{pr2}$参考文献:
如果我误解了你的问题,而这不是你想要的方向,我道歉。在
编辑:
当您想共享文件夹时,请使用以下脚本。在
示例脚本:
参考:
相关问题 更多 >
编程相关推荐