Search code examples
google-contacts-api

Google Contacts V3, retrieving GMail contacts only


I have the following code that works fine. But the issue is that the call retrieves thousands of contacts (most having only email). I want to download only those contacts that are listed in "Contacts" tab in GMail. I had to set a high "NumberToRetrieve" and then have to filter those with more information other than just email.

Dim cr As New ContactsRequest(settings)
Dim query As New ContactsQuery(ContactsQuery.CreateContactsUri("default"))
query.NumberToRetrieve = 5000
query.OrderBy = ContactsQuery.OrderByLastModified
query.SortOrder = ContactsQuery.SortOrderDescending

Dim f As Feed(Of Contact) = cr.Get(Of Contact)(query)

As usual this Google API is also poorly designed. At least in the .Net wrapper of the API I don't see anything that I can use to retrieve only GMail contacts or add a filter such as "where Address exists". Any inputs?

EDIT

Based on the feed back, I scrolled through all contacts groups to find the group "Contacts".

Dim groupquery As New GroupsQuery(GroupsQuery.CreateGroupsUri("default"))
            Dim fgrp As Feed(Of Group) = cr.Get(Of Group)(groupquery)
            Dim GroupAtomId As String = ""
            For Each gr In fgrp.Entries
                If gr.Title.Contains("Contacts") Then
                    GroupAtomId = gr.Id
                    Exit For
                End If
            Next

then used GroupAtomId, query.Group = GroupAtomId. Seems to be working ok.


Solution

  • For retrieving all the contacts from Contacts tab in Gmail, you have to specify the group value(Group) in the query as mentioned here and also for retrieving just the contacts in Contacts tab in Gmail, the group value would be just Contacts as shown here

    Hope that helps!