问题
I am trying to update user phone numbers on Google Apps Directory. Currently I have the API able to retrieve information on user's but when I try to set their phone numbers it just silently fails. The values do not update in the directory. It is possible I may be just missing a method that actually sends the data but I have been unable to find such a method.
My current scopes are:
$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 at saving phone numbers have been varied. I have 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 a variety of values for the type array structures. Any help would be greatly appreciated.
回答1:
In order to update the phone number in the directory, you need to send the information back to Google. With your code:
$google_user->setPhones(array($work_phone));
You are setting the object's phones array correctly. You still need to update that user however. You were correct when you said:
I may be just missing a method that actually sends the data
You would 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);
Relevent API documentation can be found here: https://developers.google.com/admin-sdk/directory/v1/reference/users/update
来源:https://stackoverflow.com/questions/25718487/cannot-update-user-information-using-google-php-api-client-library