我有一个域范围授权的服务帐户设置。我想通过一次通话在所有用户中搜索文件。
我使用Drive API和Google Apps脚本中的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');
由于
答案 0 :(得分:0)
您可以尝试通过Drive API从应用脚本访问的Advanced Drive Service。与DriveApp相比,它具有其他功能,允许您使用搜索查询。您还可以使用API Explorer来测试您的请求。例如,将查询字符串从Advanced Drive Service页面复制到API Explorer的q
字段中。该查询字符串为"root" in parents and trashed = false and mimeType = "application/vnd.google-apps.folder"
。如果您再单击执行,您将看到结果。查询字符串的语法解释为here。