Can't seem to add existing contact to existing contact group

147 views
Skip to first unread message

KvB

unread,
Jul 18, 2009, 4:25:05 PM7/18/09
to Google Contacts API
Hi all,

I'm trying to make my way through the google contacts api in java and
I want to be able to add or delete contacts from contact groups. So
far I haven't been succesful and I now have the following error.

When I run this code:

private void archiveContact(ContactEntry contact) throws Exception {
if (ARCHIVE_GROUP_ID == null) {
getArchiveGroupId();
}

GroupMembershipInfo gmsi = new GroupMembershipInfo();
gmsi.setHref(ARCHIVE_GROUP_ID);
contact.addGroupMembershipInfo(gmsi);

URL editUrl = new URL(contact.getEditLink().getHref());
myService.update(editUrl, contact);

}

I get this error:
com.google.gdata.util.InvalidEntryException: Bad Request
Group membership information not supported.

Does anyone have a working example of java usage of the api to add/
remove existing contacts to/from existing contact groups? Or can
anyone help me solve the error above?

Regards and thanks for any help in advance!

Julian (Google)

unread,
Jul 20, 2009, 8:45:58 AM7/20/09
to Google Contacts API
Hi,

I think the problem you are getting is because you need to use/get the
FULL protection for the Contact Entry, here is a small sample that
adds a user to an existing group:

URL entryUrl = new URL( "http://www.google.com/m8/feeds/contacts/
user%40domain.com/full/7fbb8e628be1182a" );
ContactEntry contactEntry = contactsService.getEntry
( entryUrl,ContactEntry.class);

GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo
();
groupMembershipInfo.setHref("http://www.google.com/m8/feeds/groups/
user%40domain.com/base/5ae379bc0bdda49a");
contactEntry.addGroupMembershipInfo(groupMembershipInfo);
contactEntry.update();

Cheers,
Julian.

Kees van Bemmel

unread,
Jul 20, 2009, 9:21:37 AM7/20/09
to google-co...@googlegroups.com
Hi Julian,

Thanks for the help! Would you happen to have a working piece of code
lying around which deletes a contact from a group?

Regards,

Kees.

Op 20 jul 2009 om 14:45 heeft "Julian (Google)" <j...@google.com> het
volgende geschreven:\

Julian (Google)

unread,
Jul 20, 2009, 9:28:05 AM7/20/09
to Google Contacts API
Hi Kees,

It is really similar to the one before, get an Entry and call the
delete() function:

URL entryUrl = new URL( "http://www.google.com/m8/feeds/contacts/user
%40domain.com/full/7fbb8e628be1182a" );
ContactEntry contactEntry = contactsService.getEntry
( entryUrl,ContactEntry.class);
contactEntry.delete();

--Julian

Julian (Google)

unread,
Jul 20, 2009, 9:38:28 AM7/20/09
to Google Contacts API
Hi Kees,

Sorry, the example before, is to delete a contact.

You need to edit the List<GroupMembershipInfo> and remove the group,
then update the Contact Entry. For example this removes the first
group:

URL entryUrl = new URL( "http://www.google.com/m8/feeds/contacts/user
%40domain.com/full/7fbb8e628be1182a" );
ContactEntry contactEntry = contactsService.getEntry
( entryUrl,ContactEntry.class);
contactEntry.getGroupMembershipInfos().remove(0);
contactEntry.update();

--Julian.

Kees van Bemmel

unread,
Jul 23, 2009, 2:42:07 PM7/23/09
to google-co...@googlegroups.com
Hi Julian,

Thanks so much for your help, I've got everything working!

For the record, it might be good for Google to take a look into this:

http://www.google.com/support/forum/p/Calendar/thread?fid=4da91b6497363b2f00046f63d26219ac&hl=en

Since it's pretty popular.

Thanks again!

Regards,

Kees.

FireGuy

unread,
Feb 18, 2011, 9:24:46 AM2/18/11
to google-co...@googlegroups.com
Hi Julian,

how to add a new contact in existing contact group,
Please provide piece of code.

Thanks,
Arul
Reply all
Reply to author
Forward
0 new messages