如何在群组内的Google中创建联系人

时间:2014-09-22 18:00:48

标签: java gdata google-contacts

任何机构都可以告诉我如何在群组下创建一个谷歌联系人,就像我有一个按姓名分组的群组,我希望添加联系人。现在我能够建立联系,但是在我使用

的代码之后它会在其他人之下
ContactEntry contact = new ContactEntry();
contact.setTitle(new PlainTextConstruct("chetan"));
contact.setContent(new PlainTextConstruct("sharma"));

Email primaryMail = new Email();
primaryMail.setAddress("newcontact@gmail.com");
primaryMail.setRel("http://schemas.google.com/g/2005#home");
primaryMail.setPrimary(true);
contact.addEmailAddress(primaryMail);

ExtendedProperty favouriteFlower = new ExtendedProperty();
favouriteFlower.setName("favourite flower");
favouriteFlower.setValue("daisy");
contact.addExtendedProperty(favouriteFlower);


//URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/defaults/full");
contact = service.insert(feedUrl, contact);
GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo(false, "http://www.google.com/m8/feeds/groups/defaults/base/39eb8f59897bac4d");
//groupMembershipInfo
contact.addGroupMembershipInfo(groupMembershipInfo);

2 个答案:

答案 0 :(得分:0)

我在添加groupMembershipInfo之前看到您正在插入联系人。如果要将组成员资格详细信息添加到联系人,请移动此行" contact = service.insert(feedUrl,contact);"作为代码的最后一行。

您可以参考此page了解详情。

希望有所帮助!

答案 1 :(得分:0)

您可以执行以下方法并获取帐户中不同群组的Atom ID,例如我的联系人,家人等。

public static void printAllGroups(ContactsService myService)
        throws ServiceException, IOException {
      // Request the feed
      URL feedUrl = new URL("https://www.google.com/m8/feeds/groups/ankit.ab2502@gmail.com/full");
      ContactGroupFeed resultFeed = myService.getFeed(feedUrl, ContactGroupFeed.class);

      for (ContactGroupEntry groupEntry : resultFeed.getEntries()) {
        System.out.println("Atom Id: " + groupEntry.getId());
        System.out.println("Group Name: " + groupEntry.getTitle().getPlainText());
      }
}

家庭组的此方法输出如下:

Atom Id:http://www.google.com/m8/feeds/groups/UR_EMAIL_ID/base/e

使用此网址将联系人添加到家庭群组

 GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo(false, "http://www.google.com/m8/feeds/groups/UR_EMAIL_ID/base/e");
                 contact.addGroupMembershipInfo(groupMembershipInfo);