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("https://www.google.com/m8/feeds/contacts/"+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());
       name=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());
         }else{
           contactDTO=new InstrumentDTO(email.getAddress(), email.getAddress());
         }
         myGmailContactList.add(contactDTO);
       }
       LogManager.info(this, 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) {
super();
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=")
.append(value).append("]");
return builder.toString();
}


}

-------------------------------------------------------------

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


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




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

Comments

  1. Hi,

    Please send the code to "illuminataks@gmail.com".

    Thanks,

    Aks

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

    thanks
    Bipin

    ReplyDelete
  3. can u plz send me code to
    sidduyerpula@gmail.com

    ReplyDelete
  4. hi can u send me the mail goliarun@gmail.com

    ReplyDelete
  5. Please send me the code. Feels great to understand google API and services. email id: pavan.kulkarni45@gmail.com

    ReplyDelete
  6. hi can u send me the code.
    send mail to this id ppushparaj87@gmail.com

    ReplyDelete
  7. Please send me complete code on my mail Id dnyaneshwardukare2@gmail.com

    ReplyDelete
  8. Please send me the complete code.

    balujavac@gmail.com

    ReplyDelete
  9. could u send me complete code pls.... rajlaxmi126@gmail.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Read Excel using Apache POI - Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException:

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'