【问题标题】:Scan Drive Contents of Google App Domain Users扫描 Google App 域用户的云端硬盘内容
【发布时间】:2016-02-10 05:57:44
【问题描述】:

据我所知,我似乎需要在开发者控制台中设置一个服务帐户来单独模拟每个用户。

我需要能够启动脚本(最好从 Web Apps 脚本)来扫描所有学生的 Google 云端硬盘,以监控违反政策的内容。

因此,使用类似“source:domain type:image”的云端硬盘搜索将不起作用,因为这些仅适用于共享文件。

从这里:https://developers.google.com/drive/v3/reference/files/list 我没有看到指定 userKey 的方法,就像您可以使用 Admin SDK API 那样。

【问题讨论】:

    标签: google-apps-script google-api


    【解决方案1】:

    是的,正如您所说,您需要使用服务帐户。当您使用OAuth2 library 的服务帐户时,您可以设置“主题”(您要模拟的用户帐户)。图书馆有一个service account sample

    这是一个稍作修改的 OAuth2.getService() 示例,它将用户帐户电子邮件作为参数。当您遍历您的用户列表时,您将在每个 https://developers.google.com/drive/v3/reference/files/list Drive API 调用之前运行它。

    /**
     * Configures the service.
     */
    function getService(userEmail) {
      return 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');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多