我有一个 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) 共享。任何建议表示赞赏!
扬帆大鱼
相关分类