1

Google Admin API を使用して、ドメインのユーザーを取得して更新しようとしています。

  private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
  private static final List<String> SCOPES = Arrays.asList(
      "https://www.googleapis.com/auth/admin.directory.user",
      "https://www.googleapis.com/auth/admin.directory.user.readonly");

  public static void main(String[] args) {
    try {
      HttpTransport httpTransport = new NetHttpTransport();


      GoogleCredential credential =
          new GoogleCredential.Builder()
              .setTransport(httpTransport)
              .setJsonFactory(JSON_FACTORY)
              .setServiceAccountId(
                  "xxxxx-yyyyy@developer.gserviceaccount.com")
              .setServiceAccountUser("superadmin@mydomain.com")
              .setServiceAccountScopes(SCOPES)
              .setServiceAccountPrivateKeyFromP12File(
                  new File("C:\\privatekey.p12")).build();

      Directory admin =
          new Directory.Builder(httpTransport, JSON_FACTORY, credential)
              .setApplicationName("User Sync Service")
              .setHttpRequestInitializer(credential).build();

      Directory.Users.List list = admin.users().list();
      Users users = list.execute();
      System.out.println("************");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

Google コンソールから

ここに画像の説明を入力 ここに画像の説明を入力

  1. セキュリティ パネルから API アクセスが有効になっている
  2. ServiceAccountUser はスーパー管理者です。

しかし、私はまだこのエラーが発生しています

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "access_denied"
}
    at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
    at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
    at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:269)
    at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
    at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:858)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)

更新: ManageOath のスクリーンショット

ここに画像の説明を入力

4

3 に答える 3

3

ドキュメントは、顧客とドメインについてややあいまいであるようです。いずれかを指定する必要があります。customerlist() 関数を使用すると、属性を設定できます。顧客の ID (一意でランダムに見える文字列) に設定する必要があります。または、既に Google Apps インスタンスで管理者として認証している場合は、正確にcustomer=my_customer. domain=example.comまたは、 example.com が Google Apps インスタンスのプライマリ ドメインまたはセカンダリ ドメインである場所を指定することもできます。ドメインを指定すると、そのドメインにプライマリ (ホーム) アドレスを持つユーザーのみが結果に返されます。顧客を指定すると、Google Apps インスタンス内のすべてのユーザーが返されます。

これは、 Google API Explorerを使用して確認できます。顧客を空白のままにすると、常にエラーになります。ただし、my_customer顧客属性を指定すると修正されるはずです。

于 2013-09-10T12:47:47.020 に答える
0

https://admin.google.com/ yourdomain /ManageOauthClientsに進み、これらのスコープが xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com サービス アカウント ID に追加されていることを確認します。

于 2013-09-10T10:59:41.470 に答える