为了账号安全,请及时绑定邮箱和手机立即绑定

使用 gspread 创建的电子表格正在与我组织中的所有用户共享

使用 gspread 创建的电子表格正在与我组织中的所有用户共享

郎朗坤 2022-05-11 16:26:10
我有一个 Python 脚本,它解析 HTML 文件并将我需要的信息放入由服务帐户创建并与我共享的 Google 表格文档中。一切正常,除了生成的服务帐户拥有的电子表格不仅与我共享,而且与我 G Suite 组织中的每个人共享。没什么大不了的,因为我的组织很小,但我确信我的同事不希望这些文件弄乱他们的“与我共享”文件夹。我已经对此进行了网络搜索并仔细阅读了 Stack Overflow,但还没有想出任何想法来更改我的代码以尝试。我还想知道这是否是我需要在 Google API 控制台中更改的设置,但在那里也没有找到任何东西。以下是相关代码:import gspreadfrom oauth2client.service_account import ServiceAccountCredentialsdef loadTemplate(template_name, output_name):        # use creds to create a client to interact with the Google Drive API        print("Connecting to Google API...")        scope = ['https://www.googleapis.com/auth/drive']        creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)        client = gspread.authorize(creds)        # Make a copy of the template and name it something that uniquely identifies this report        print("Copying template...")        open_spreadsheet = client.open(template_name)        copy_spreadsheet = client.copy(open_spreadsheet.id,title=output_name, copy_permissions=True)        copy_spreadsheet.share('myname@myorganization.com', perm_type='user', role='writer', notify=False)        return copy_spreadsheettemplate_spreadsheet = loadTemplate(template_name, output_name)同样,一切都按预期运行,除了结果与我的 G Suite 组织中的所有用户共享,而不仅仅是与我 (myname@myorganization.com) 共享。任何建议表示赞赏!
查看完整描述

1 回答

?
扬帆大鱼

TA贡献1799条经验 获得超9个赞

我想通了,我觉得很愚蠢...

我正在复制模板,然后设置copy_permissions=True. 该模板实际上并未与我的整个组织共享,而是我碰巧检查过的两个人共享,因此默认情况下,它的每个副本都与相同的两个人共享。更改以copy_permissions=False解决问题。


查看完整回答
反对 回复 2022-05-11
  • 1 回答
  • 0 关注
  • 256 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号