将联系人添加到特定组? Google Contact API

时间:2010-03-10 07:57:15

标签: c# contact

我正在使用Google Contact API将联系人和群组添加到Google Apps(gmail)中。 我可以创建联系人和群组。

但现在我想:

  1. 在创建联系人时将联系人置于特定群组。

2 个答案:

答案 0 :(得分:2)

/* Get Group, this is covered in the Google Contact API documents */
/* http://code.google.com/apis/contacts/docs/2.0/developers_guide_dotnet.html#retrieving_single_group */

Group group = ...; 

Contact newContact = new Contact();

var groupMembership = new GroupMembership();
groupMembership.HRef= group.Id;


newContact.Title = "My google contact title";
newContact.GroupMembership.Add(groupMembership);

/* Save the contact, also covered in the documents */
/* http://code.google.com/apis/contacts/docs/2.0/developers_guide_dotnet.html#Creating */

答案 1 :(得分:0)

以下为我工作:

Group g = cr.Retrieve<Group>(new Uri("https://www.google.com/m8/feeds/groups/liz%40gmail.com/base/68f415478ba1aa69"));

newEntry.GroupMembership.Add(new GroupMembership() { HRef = g.Id });