简体   繁体   中英

Google Directory API cannot insert or patch user property in Java

I want to create user account and user's Optional Properties (ex. addresses, emails, externalIds, ims, phones, organizations) using Directory API Users-insert. But when I check the insert result, only 4 property can be see (familyName, givenName, password, primaryEmail),but others field doesn't work, and the request is fine with status code 200.

And I try Users- Update or Patch to Optional Properties, and also the request is fine with status code 200, but i cannot see my changes in my user profile.

What do I need to do can create these Optional properties ?

My current scopes are:

private static final String[] tscopes = { 
                "https://www.googleapis.com/auth/admin.directory.user" ,
                "https://www.googleapis.com/auth/admin.directory.orgunit",
            };

Using Users-insert:

User user = new User();
UserOrganization uorg = new UserOrganization();
UserPhone uphone = new UserPhone();
UserName uname = new UserName();

uname.setFamilyName("A").setGivenName("BC");
uorg.setTitle("Engineer").setCostCenter("CA").setDepartment("IT");
uphone.setValue("00-2345678").setType("work");

user.setName(uname).setPassword("abcd").setPrimaryEmail("abc@mydomain.com").setOrganizations(uorg).setPhones(uphone);

Directory.Users.Insert dui = service.users().insert(user);
dui.execute();

getLastResponseHeaders:

{cache-control=[no-cache, no-store, max-age=0, must-revalidate], content-encoding=[gzip], content-type=[application/json; charset=UTF-8], date=[Wed, 05 Oct 2016 10:35:23 GMT], etag=["xxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx"], expires=[Mon, 01 Jan 1990 00:00:00 GMT], transfer-encoding=[chunked], alt-svc=[quic=":443"; ma=2592000; v="36,35,34,33,32"], server=[GSE], x-content-type-options=[nosniff], pragma=[no-cache], x-frame-options=[SAMEORIGIN], vary=[X-Origin, Origin], x-xss-protection=[1; mode=block]}

getLastStatusCode: 200

If you are trying to view these properties through the Google Admin Console, not all of them are displayed there.
You can create a user and then perform a GET for that user which will bring in all properties of the user. You can try Google's Try It to perform this GET.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM