使用 gspread 创建的电子表格正在与我组织中的所有用户共享
Spreadsheets created using gspread are being shared with all users in my organization
我有一个 Python 脚本来解析 HTML 文件并将我需要的信息放入 Google 表格文档中,该文档由服务帐户创建并共享给我。一切正常,除了生成的服务帐户拥有的电子表格不仅与我共享,而且与我的 G Suite 组织中的每个人共享。没什么大不了的,因为我的组织很小,但我确信我的同事不希望这些文件弄乱他们的 "Shared with me" 文件夹。
我已经通过网络搜索了这个问题并仔细阅读了 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) 共享的。任何建议表示赞赏!
我想通了,我觉得自己很傻...
我是复制一个模板,设置copy_permissions=True
。该模板实际上并没有与我的整个组织共享,但它 是 与我偶然联系的两个人共享的,因此默认情况下它的每个副本都与一样的两个人更改为 copy_permissions=False
解决了问题。
我有一个 Python 脚本来解析 HTML 文件并将我需要的信息放入 Google 表格文档中,该文档由服务帐户创建并共享给我。一切正常,除了生成的服务帐户拥有的电子表格不仅与我共享,而且与我的 G Suite 组织中的每个人共享。没什么大不了的,因为我的组织很小,但我确信我的同事不希望这些文件弄乱他们的 "Shared with me" 文件夹。
我已经通过网络搜索了这个问题并仔细阅读了 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) 共享的。任何建议表示赞赏!
我想通了,我觉得自己很傻...
我是复制一个模板,设置copy_permissions=True
。该模板实际上并没有与我的整个组织共享,但它 是 与我偶然联系的两个人共享的,因此默认情况下它的每个副本都与一样的两个人更改为 copy_permissions=False
解决了问题。