0

我正在尝试使用 Google Directory API。在我的项目中,我启用了 Admin SDK、Google+ Domains API。

JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

ArrayList<String> scopeList = new ArrayList<>();
scopeList.add(DirectoryScopes.ADMIN_DIRECTORY_USER);
scopeList.add(DirectoryScopes.ADMIN_DIRECTORY_USER_READONLY);

GoogleCredential credential = new GoogleCredential.Builder()
      .setTransport(httpTransport)
      .setJsonFactory(JSON_FACTORY)
      .setServiceAccountId("bla-bla@developer.gserviceaccount.com")
      .setServiceAccountScopes(scopeList)
      .setServiceAccountPrivateKeyFromP12File(new File("c:/my-file.p12"))
      .setServiceAccountUser("logined-user-email")
      .build();

credential.setAccessToken(<accessToken from OAuth to google>);
Directory admin = new Directory.Builder(httpTransport, JSON_FACTORY, credential)
          .setApplicationName("Test")
          .setHttpRequestInitializer(credential).build();


Users users = admin.users().list().setDomain("my-domain.com").execute();

=> "域不能使用 api "

我的错误在哪里?

4

1 回答 1

1

要使用 Admin SDK API,域管理员需要在管理控制台中“启用 API 访问”。请参考这里

于 2014-10-13T13:28:43.487 回答