我有一個服務帳戶設置與域寬委派。我想通過一次通話在所有用戶中搜索文件。獲取所有用戶的所有云端硬盤文件
我在Google Apps腳本中使用Drive API和OAuth2項目來處理身份驗證。看起來你總是必須指定一個用戶在進行調用時模擬(下面的代碼)。當我刪除setSubject方法時,我沒有得到任何結果。
有沒有辦法做到這一點?
OAuth2.createService('GoogleDrive:' + userEmail)
// Set the endpoint URL.
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
// Set the private key and issuer.
.setPrivateKey(PRIVATE_KEY)
.setIssuer(CLIENT_EMAIL)
// Set the name of the user to impersonate. This will only work for
// Google Apps for Work/EDU accounts whose admin has setup domain-wide
// delegation:
// https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority
.setSubject(userEmail)
// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getScriptProperties())
// Set the scope. This must match one of the scopes configured during the
// setup of domain-wide delegation.
.setScope('https://www.googleapis.com/auth/drive');
感謝
你是正確使用服務帳戶設置與域寬委派。如此[線程](http://stackoverflow.com/a/13732646/5832311)中所述,您應該使用Google Drive API並使用服務帳戶執行[Google Apps域範圍授權](https:/ /developers.google.com/drive/delegation)。 – abielita
根據此[文檔](https://developers.google.com/apps-script/reference/drive/),您需要返回['FileIterator'](https://developers.google.com/apps -script/reference/drive/file-iterator),它允許腳本遍歷潛在的大量文件集合。以下是一個示例[代碼](https://productforums.google.com/forum/#!topic/docs/7ZQgzbcSX68)。 – abielita
@abielita對不起,我不夠具體。我已經使用帶有服務帳戶的Drive API。我在上面的文章中留了更多細節。謝謝 – jadent