Search code examples
javagoogle-contacts-api

How to fetch contacts from Gmail


I have seen Google Contacts API but I am not getting any thing I want to fetch email contacts from logged in users.

I found a simple example with php which is very easy but I am not able to convert it in to java. I am trying with Google contact API problem is the import statement is showing error.

How to import these.

 import com.google.gdata.client.*;
 import com.google.gdata.client.contacts.*;
 import com.google.gdata.data.*;
 import com.google.gdata.data.contacts.*;
 import com.google.gdata.data.extensions.*;
 import com.google.gdata.util.*;
 import java.io.IOException;

I am not getting jar file for these imports. If is there any example other than google please give links.


Solution

  • I found the following maven entry:

    <dependency>
      <groupId>com.google.gdata</groupId>
      <artifactId>gdata-contacts-3.0</artifactId>
      <version>1.41.5</version>
    </dependency>
    

    supported the following imports, which allowed me to access the gmail contacts

    import com.google.gdata.client.Service.GDataRequest;
    import com.google.gdata.client.contacts.ContactsService;
    import com.google.gdata.data.Link;
    import com.google.gdata.data.TextConstruct;
    import com.google.gdata.data.contacts.Birthday;
    import com.google.gdata.data.contacts.ContactEntry;
    import com.google.gdata.data.contacts.ContactFeed;
    import com.google.gdata.data.extensions.Email;
    import com.google.gdata.data.extensions.FamilyName;
    import com.google.gdata.data.extensions.FormattedAddress;
    import com.google.gdata.data.extensions.GivenName;
    import com.google.gdata.data.extensions.Name;
    import com.google.gdata.data.extensions.OrgName;
    import com.google.gdata.data.extensions.Organization;
    import com.google.gdata.data.extensions.PhoneNumber;
    import com.google.gdata.data.extensions.StructuredPostalAddress;
    import com.google.gdata.util.AuthenticationException;
    import com.google.gdata.util.ContentType;
    import com.google.gdata.util.PreconditionFailedException;
    import com.google.gdata.util.ServiceException;