0

問題:我已創建服務帳戶以與我的組織的Google Drive &電子表格文件進行交互 - 我可以成功創建會話以訪問Google Drive API。但是,我有機會獲得唯一的文件是這樣的樣板:無法看到帶有服務帳戶的gSuite文件

=> [#< Google雲端硬盤::文件ID = 「aSdsefooovjTnulaRlclbarrr」 稱號= 「入門」>]

什麼水平你認爲我失蹤的權限?

我唯一能想到的就是,其他一些頂級權限隱藏來自org外部的文件。即使服務帳號是明確地在文件上共享的嗎?如果有任何指示,我會與服務帳戶分享。 enter image description here

也許與此文檔中的下列圖像有關?

https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority

enter image description here

步驟,我已經經歷了..

1)我創建了域範圍代表團和項目編輯狀態的服務帳戶。

2)我邀請的服務帳戶電子郵件至我希望它有

3)我有我的組織的gSuite管理員已經添加了該服務帳戶的CLIENT_ID到/安全API訪問張/管理API客戶端訪問..與範圍 - >https://www.googleapis.com/auth/drivehttps://spreadsheets.google.com/feeds

想盡組合,我可以在所有的文檔/教程找到。這是我的連接代碼,基於https://www.twilio.com/blog/2017/03/google-spreadsheets-ruby.html。嘗試在client_secret.json中傳遞範圍。爲服務帳戶嘗試使用iam角色的工具。

session = GoogleDrive::Session.from_service_account_key("client_secret.json")

{ 
    "type": "service_account", 
    "project_id": "gdrive-1231233", 
    "private_key_id": "food87c0bar16da9bfoooooo677bar", 
    "private_key": "-----BEGIN PRIVATE KEY-----\nsssEIEvQfooobarrrytyeho=\n-----END PRIVATE KEY-----\n", 
    "client_email": "[email protected]", 
    "client_id": "foo40990211bar", 
    "auth_uri": "https://accounts.google.com/o/oauth2/auth", 
    "token_uri": "https://accounts.google.com/o/oauth2/token", 
    "auth_provider_foox_cert_url": "https://www.googleapis.com/oauth2/v1/certs", 
    "client_foox_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/servicebot%40gdrive-foobar.iam.gserviceaccount.com" 
} 

#<GoogleDrive::Session:0v3fc6c3e25061> 

回答

0

所以原來我可以用它來找到一個明確的電子表格是spreadsheet_by_url的唯一方法 - .files .spreadsheets .find_by_guid,等等。所有返回nil。但通過url搜索直接返回的文件,並啓用我的讀/寫。

session = GoogleDrive::Session.from_service_account_key("client_secret.json") 
session.spreadsheet_by_url(ENV['GOOGLE_DATA_DUMP_URL']) 
worksheet = spreadsheet.worksheets[0]