列出团队驱动器文件:错误403权限不足

时间:2018-09-17 16:29:45

标签: google-api google-drive-api google-drive-team-drive

我正在尝试访问Team Drive的文件,但出现403错误,而我可以访问普通Google Drive的文件。

是否需要在OAuth密钥上添加特定权限?

    final NetHttpTransport HTTP_TRANSPORT =         GoogleNetHttpTransport.newTrustedTransport();
    Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
            .setApplicationName(APPLICATION_NAME)
            .build();


    String pageToken = null;
    do {
      TeamDriveList result = service.teamdrives().list()
          .setFields("nextPageToken, files(id, name)")
          .setUseDomainAdminAccess(true)
          .setPageToken(pageToken)
          .execute();
      for (TeamDrive file : result.getTeamDrives()) {
        System.out.printf("Found file: %s (%s)\n",
            file.getName(), file.getId());
      }
      pageToken = result.getNextPageToken();
    } while (pageToken != null);

响应:

    Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
    {
      "code" : 403,
      "errors" : [ {
        "domain" : "global",
        "message" : "Insufficient Permission",
        "reason" : "insufficientPermissions"
      } ],
      "message" : "Insufficient Permission"
    }

0 个答案:

没有答案