我无法弄清楚如何使用php中的google people api创建新的联系人组并将其分配给联系人。错误
“ person.memberships是一个只读字段。”
发生在$ person-> setMemberships():
$contactGroup=new Google_Service_PeopleService_ContactGroup();
//$contactGroup->setGroupType('USER_CONTACT_GROUP');
$contactGroup->setName('Some group');
$contactGroup->create();
$cgm=new Google_Service_PeopleService_ContactGroupMembership();
$cgm->setContactGroupId('groupID');
$membership=new Google_Service_PeopleService_Membership();
$membership->setContactGroupMembership($cgm);
$person=new Google_Service_PeopleService_Person();
$groupMemberships=array(($membership));
$person->setMemberships(array($groupMemberships));//error happens here
任何人都可以提供有关创建联系人组并将其分配给联系人的适当示例的帮助吗?
答案 0 :(得分:0)
您无法在创建呼叫中设置联系人组的成员。您需要在一个调用中创建联系人组,然后在第二个调用中使用members.modify api调用将其添加。
答案 1 :(得分:0)
以下代码假定您已实例化一个Google_Client
对象,并且已经创建了一个人并知道其ID。
资源ID示例,
$person_id = 'people/1234567890abcde';
创建联系人组,
$peopleService = new Google_Service_PeopleService($client);
$newContactGroup = new Google_Service_PeopleService_ContactGroup;
$newContactGroup->setName('New contact group');
$createContactGroupRequest = new Google_Service_PeopleService_CreateContactGroupRequest;
$createContactGroupRequest->setContactGroup($newContactGroup);
$contactGroup = $peopleService->contactGroups->create($createContactGroupRequest);
$contact_group_id = $contactGroup->getResourceName();
将一个人添加到联系人组,
$peopleService = new Google_Service_PeopleService($googleClient);
$modifyContactGroupMembersRequest = new Google_Service_PeopleService_ModifyContactGroupMembersRequest;
$modifyContactGroupMembersRequest->setResourceNamesToAdd($person_id);
$peopleService->contactGroups_members->modify($contact_group_id, $modifyContactGroupMembersRequest);