1
votes

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.

1
For retrieving all the contacts from "contacts" tab in Gmail, you have to specify the group value(Group) in the query as mentioned here: developers.google.com/google-apps/contacts/v3/… and also for retrieving just the contacts in "contacts" tab in Gmail, the group value would be just "Contacts" as shown here: developers.google.com/google-apps/contacts/v3/… - KRR
Thanks for pointing me to right direction. If you answer, I will accept. - Allen King
Thanks @Allen, added as an answer. - KRR

1 Answers

2
votes

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!