Search code examples
c#.netgoogle-apigoogle-contacts-api

Using Google Contacts API v3, how to get contacts for a specific group?


I am able to get contacts and groups. What I am unable to do is query contacts for a specific group. I've read the Docs, and specifying group Atom Id doesn't make sense because there is a type collision.

const string name = "MyGroup";
var uri = ContactsQuery.CreateGroupsUri("default");
var gQuery = new GroupsQuery(uri);
var group = cr.Get<Group>(gQuery).Entries.AsQueryable()
    .SingleOrDefault(e => e.GroupEntry.Title.Text.Contains(name));

uri = ContactsQuery.CreateContactsUri("default");
var cQuery = new ContactsQuery(uri);
if (group != null)
{
   cQuery.Group = (string)group.AtomEntry.Id;   //  WHAT TO PUT HERE ?
}
Feed<Contact> feed = cr.Get<Contact>(cQuery);

Unable to assign type AtomId...

group.AtomEntry.Id // type = AtomId

... to string type for ...

cQuery.group // type = string

Thanks!


Solution

  • Change...

    cQuery.Group = (string)group.AtomEntry.Id;
    

    to...

    cQuery.Group = (string)group.Id;
    

    The hint came from this post. Where I realized that the URI being constructed is quite long and includes [the contacts URI] + ?group= [the group base/id URI]. Example: https://www.google.com/m8/feeds/contacts/default/full?group=http://www.google.com/m8/feeds/groups/user.email%40domain.com/base/some_alphanumeric_id