Get contact list from Gmail account using java

You can get all contacts exists in your gmail account using this program...

First you will need the jar file gdata (library files for fetching data from google)...
public static  List<ContactDTO> getAllGmailContacts(String gmailId,String password)
throws ServiceException, IOException {
InstrumentDTO contactDTO;
String name;
List<ContactDTO> myGmailContactList= new ArrayList<ContactDTO>();

ContactsService myService = new ContactsService("Find_Contacts_On_Gmail");
myService.setUserCredentials(gmailId, password);

    URL feedUrl = new URL(""+gmailId+"/full");

    ContactFeed resultFeed = myService.getFeed(feedUrl, ContactFeed.class);  
    for (int i = 0; i < resultFeed.getEntries().size(); i++) {
       ContactEntry entry = resultFeed.getEntries().get(i);
       System.out.println("\t" + entry.getTitle().getPlainText());
       for (Email email : entry.getEmailAddresses()) {  
    System.out.println("Friend Name:"+name+" and emailAddress:"+email.getAddress());

         if(name != null && name.trim().length()>0){
           contactDTO=new InstrumentDTO(name, email.getAddress());
           contactDTO=new InstrumentDTO(email.getAddress(), email.getAddress());
       }, resultFeed.getTitle().getPlainText()+" list size (Gmail contact list):"+myGmailContactList.size());  
    return myGmailContactList;


public class ContactDTO {

private String key;
private String value;

public ContactDTO() {

public ContactDTO(String key, String value) {
this.key = key;
this.value = value;
public String getKey() {
return key;
public void setKey(String key) {
this.key = key;
public String getValue() {
return value;
public void setValue(String value) {
this.value = value;

public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ContactDTO [key=").append(key).append(", value=")
return builder.toString();



Iterate this ContactDTO list on jsp using following code.....

   <s:if test="myGmailContactList!=null">
       <tr bgcolor="red" bordercolor="RED">
           <td>Friend Name</td>
           <td>Email Address</td>
       <s:iterator value="myGmailContactList" >
         <tr><td><s:property value="key" /></td>
             <td><s:property value="value" /></td>

For complete code send mail to us..............


  1. Hi,

    Please send the code to "".



  2. Hi,
    Great work!!!
    can you please send me the complete code on my id that is


  3. can u plz send me code to

  4. hi can u send me the mail

  5. Please send me the code. Feels great to understand google API and services. email id:

  6. hi can u send me the code.
    send mail to this id

  7. Please send me complete code on my mail Id

  8. Please send me the complete code.

  9. could u send me complete code pls....


Post a Comment

Popular posts from this blog

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Struts 2 - struts tag with boolean property