Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在组内的Google中创建联系人_Java_Gdata_Google Contacts Api - Fatal编程技术网

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

Java 如何在组内的Google中创建联系人,java,gdata,google-contacts-api,Java,Gdata,Google Contacts Api,任何人都可以告诉我如何在群组下创建一个google联系人,就像我有一个名为group的群组一样,我想在这个群组下添加联系人。现在我可以创建联系人,但它将在我使用的其他代码下运行 ContactEntry contact = new ContactEntry(); contact.setTitle(new PlainTextConstruct("chetan")); contact.setContent(new PlainTextConstruct("sharma")); Email prima

任何人都可以告诉我如何在群组下创建一个google联系人,就像我有一个名为group的群组一样,我想在这个群组下添加联系人。现在我可以创建联系人,但它将在我使用的其他代码下运行

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);

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

有关更多详细信息,请参阅此


希望有帮助

您可以执行下面的方法并获取帐户中不同组(如我的联系人、家庭成员等)的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:

使用此url可将联系人添加到家庭组

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