google people api:分配/创建联系人组 [英] google people api: assign/create contact group

查看:96
本文介绍了google people api:分配/创建联系人组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何使用php中的google people api创建新的联系人组并将其分配给联系人.错误

I cannot figure out how to create a new contact group and assign it to the contact using google people api in php. An error

"person.memberships是一个只读字段."

"person.memberships is a read only field."

发生在$ person-> setMemberships():

occurs at $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

任何人都可以提供有关创建联系人组并将其分配给联系人的适当示例的帮助吗?

Anyone could help with a proper example of creating contact group and assigning it to the contact?

推荐答案

以下代码假定您已实例化Google_Client对象,并且已经创建了一个人并知道其ID.

The following code assumes you have instantiated a Google_Client object, and have already created a person and know their 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();

将一个人添加到联系人组,

Add a person to contact group,

$peopleService = new Google_Service_PeopleService($googleClient);

$modifyContactGroupMembersRequest = new Google_Service_PeopleService_ModifyContactGroupMembersRequest;
$modifyContactGroupMembersRequest->setResourceNamesToAdd($person_id);

$peopleService->contactGroups_members->modify($contact_group_id, $modifyContactGroupMembersRequest);

这篇关于google people api:分配/创建联系人组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆