我有一個 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('[email protected]', perm_type='user', role='writer', notify=False) return copy_spreadsheettemplate_spreadsheet = loadTemplate(template_name, output_name)同樣,一切都按預期運行,除了結果與我的 G Suite 組織中的所有用戶共享,而不僅僅是與我 ([email protected]) 共享。任何建議表示贊賞!
1 回答

揚帆大魚
TA貢獻1799條經驗 獲得超9個贊
我想通了,我覺得很愚蠢...
我正在復制模板,然后設置copy_permissions=True
. 該模板實際上并未與我的整個組織共享,而是與我碰巧檢查過的兩個人共享,因此默認情況下,它的每個副本都與相同的兩個人共享。更改以copy_permissions=False
解決問題。
添加回答
舉報
0/150
提交
取消