Can't update user information with Google PHP API client library
I am trying to update user phone numbers in Google Apps Directory. I currently have an API capable of fetching user information, but when I try to set their phone numbers, it just fails. Values are not updated in the catalog. Maybe I'm just missing a method that actually sends data, but I couldn't find such a method.
My current areas:
$scopes = array('https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.orgunit');
My attempts to store phone numbers have changed. I tried:
$work_phone = new \Google_Service_Directory_UserPhone();
$work_phone->setType('work');
$work_phone->setValue($work_number);
$google_user->setPhones(array($work_phone));
and
$google_user->setPhones(array(array(
"type"=>"work",
"value"=>$work_number
)));
As well as the set of values for array structures of types. Any help would be greatly appreciated.
source to share
To update a directory phone number, you need to send the information back to Google. With code:
$google_user->setPhones(array($work_phone));
The array of objects is configured correctly. However, you still need to update this user. You were right when you said:
Perhaps I am just missing a method that actually sends the data
You will need to do something like this:
$work_phone = new \Google_Service_Directory_UserPhone();
$work_phone->setType('work');
$work_phone->setValue($work_number);
$google_user->setPhones(array($work_phone));
$serviceDirectory = new Google_Service_Directory($client);
$serviceDirectory->users->update($google_user);
The relevant API documentation can be found here: https://developers.google.com/admin-sdk/directory/v1/reference/users/update
source to share