谷歌目录api“域名不能使用apis”

时间:2014-06-20 11:19:04

标签: google-apps google-admin-sdk google-directory-api

我正在尝试使用Google Directory API。 在我的项目中,我启用了管理员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();

=&GT; “域名无法使用apis

我的错误在哪里?

1 个答案:

答案 0 :(得分:1)

要使用Admin SDK API,域管理员需要&#34;启用API访问&#34;在管理控制台中。请参阅this