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

我有一个 Python 脚本,它解析 HTML 文件并将我需要的信息放入由服务帐户创建并与我共享的 Google 表格文档中。一切正常,除了生成的服务帐户拥有的电子表格不仅与我共享,而且与我 G Suite 组织中的每个人共享。没什么大不了的,因为我的组织很小,但我确信我的同事不希望这些文件弄乱他们的“与我共享”文件夹。


我已经对此进行了网络搜索并仔细阅读了 Stack Overflow,但还没有想出任何想法来更改我的代码以尝试。我还想知道这是否是我需要在 Google API 控制台中更改的设置,但在那里也没有找到任何东西。


以下是相关代码:


import gspread

from oauth2client.service_account import ServiceAccountCredentials


def 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_spreadsheet


template_spreadsheet = loadTemplate(template_name, output_name)

同样,一切都按预期运行,除了结果与我的 G Suite 组织中的所有用户共享,而不仅仅是与我 (myname@myorganization.com) 共享。任何建议表示赞赏!


郎朗坤
浏览 257回答 1
1回答

扬帆大鱼

我想通了,我觉得很愚蠢...我正在复制模板,然后设置copy_permissions=True. 该模板实际上并未与我的整个组织共享,而是与我碰巧检查过的两个人共享,因此默认情况下,它的每个副本都与相同的两个人共享。更改以copy_permissions=False解决问题。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python