- ライブラリ: google-api-services-admin-directory_v1-rev11-1.16.0-rc.jar
- API コンソール : サービス アカウント
- ドメイン サードパーティ OAuth クライアント アクセス設定 https://www.googleapis.com/auth/admin.directory.group https://www.googleapis.com/auth/admin.directory.user
ユーザー リストの取得は機能しますが、グループ リストはエラーを返します (access_denied)
ソース
scopeList.add(DirectoryScopes.ADMIN_DIRECTORY_USER);
scopeList.add(DirectoryScopes.ADMIN_DIRECTORY_GROUP);
scopeList.add(DirectoryScopes.ADMIN_DIRECTORY_GROUP_MEMBER);
credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("xxxxx@developer.gserviceaccount.com")
.setServiceAccountScopes(scopeList)
.setServiceAccountPrivateKeyFromP12File(new java.io.File("xxxxx-privatekey.p12"))
.setServiceAccountUser("admin@test.com")
.build();
Directory admin = new Directory.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Test")
.setHttpRequestInitializer(credential).build();
admin.users().list().setDomain("test.com").execute();
admin.groups().list().setDomain("test.com").execute();
エラー
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:332)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:352)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:269)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:454)
at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:215)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:854)
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)