0

Here is my credential built using service account,

GoogleCredential credential = new GoogleCredential.Builder()
             .setJsonFactory(jsonFactory).setTransport(httpTransport)

     .setServiceAccountId("xxxxxxx@developer.gserviceaccount.com")
     .setServiceAccountPrivateKeyFromP12File(new File("key.p12"))

     .setServiceAccountScopes(Collections.singleton(DirectoryScopes.ADMIN_DIRECTORY_USER))

     .build();

And all I am trying is to get a user, where User is com.google.api.services.admin.directory.model.User

User u = null;
try {
    u = service.users().get("test@gmail.com").execute();
} catch (Exception e) {

    e.printStackTrace();
}

    return u.toPrettyString();
}

response returns with code 404 Resource not found?? Is it user need to be created? how to access any gmail user?

4

1 回答 1

2

假设您已经授予您的服务帐户域范围委派,您需要让它模拟管理员帐户.setServiceAccountUser("admin@domain.com"),如服务帐户文档中所示。服务帐户本身不是域管理员,因此他们需要模拟一个才能使用 Admin SDK API。

于 2014-10-23T20:21:56.690 回答