问题描述
我正在尝试更新Google Apps目录中的用户电话号码.目前,我拥有能够检索用户信息的API,但是当我尝试设置他们的电话号码时,它只是默默地失败了.值不会在目录中更新.可能我可能只是缺少一种实际发送数据的方法,但我一直找不到这种方法.
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.
我当前的范围是:
$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));
还有
$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.
推荐答案
为了更新目录中的电话号码,您需要将信息发送回Google.使用您的代码:
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:
您需要执行以下操作:
$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文档可在以下位置找到: https://developers.google.com/admin-sdk/directory/v1/reference/users/update
Relevent API documentation can be found here: https://developers.google.com/admin-sdk/directory/v1/reference/users/update
这篇关于无法使用Google PHP API客户端库更新用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!