Click here to Skip to main content
Click here to Skip to main content

Tagged as

Fetch Gmail Contacts

, 24 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Hi All,
In this article, we will see how to fetch Gmail contacts list & show it in grid view. You need to follow below steps to complete this task
  1. Download Google Data API Dlls
  2. Extract Google MSI component
  3. Implement Code to fetch contacts
Download Google Data API Dlls: Open the below link & click, download Google_Data_API_Setup_1.9.0.0.ms
http://code.google.com/p/google-gdata/downloads/list

Extract Google MSI

Double click the downloaded MSI component & provide the path to extract the code. Usually it will extract into c:\Program file. To fetch the DLL, go to C:\Program Files\Google\Google Data API SDK\Samples

Implement Code to Fetch Contacts

  1. Create a new website
  2. Copy the below dll from above sample path & add below dll to your solution

    1. Google.GData.Client
    2. Google.GData.Contacts
    3. Google.GData.Extensions
  3. Add a new webpage to solution & name it as "contactlist.aspx" Now add the below grid view to the page
    <asp:GridView ID="GridView1" AutoGenerateColumns="true" 
        runat="server" BackColor="Aquamarine" ForeColor="Black" BorderColor="OrangeRed" 
        Font-Names="Comic Sans MS" Width="525">
                  <alternatingrowstyle backcolor="Aqua" />
    <HeaderStyle BackColor="Crimson" Font-Italic="false" ForeColor="Snow" />

  4. Go to .aspx.cs page and following code & also add following to the class
    using Google.GData.Client;
    using Google.Contacts;
    using Google.GData.Extensions;
     
    private void FetchContactList()
        {
    	
            // Define string of list
          List<string> lstContacts = new List<string>();
     
    	  // Below requestsetting class take 3 parameters applicationname, gmail username, gmail password. 
    	  // Provide appropriate Gmail account details
            RequestSettings rsLoginInfo = new RequestSettings("", "suryabg2000@gmail.com", "XXXXXX");
            rsLoginInfo.AutoPaging = true;
     
            ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);
     
            // fetch contacts list
            Feed<contact> feedContacts = cRequest.GetContacts();
     
    	 // looping the feedcontact entries
            foreach (Contact gmailAddresses in feedContacts.Entries)
            {
     
               // Looping to read email addresses
                foreach (EMail emailId in gmailAddresses.Emails)
                {
    		
                    lstContacts.Add(emailId.Address);
                }
     
            }
     
            // finally binding the list to gridview defined in above step
    
            GridView1.DataSource = lstContacts;
            GridView1.DataBind();
     
        }
Finally you will be able to see the data in the gridview
 
Happy Koooding… Hope this helps!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bangla Gopal Surya Prakash
Software Developer (Senior)
United States United States
B.Tech graduate in CSE, having experience in .Net related Technologies
 
Microsoft Certified Technical Specialist in .NET Framework 2.0
Microsoft Certified Technical Specialist in .NET Framework 4.0
 
My interests are Coding, reading [technical stuff] and listening to music, playing Cricket, Table Tennis
 
http://bgsuryablog.blogspot.com/

Comments and Discussions

 
GeneralMy vote of 4 PinmemberSudhakar Shinde24-Apr-13 2:31 
QuestionIs Google Contact API dead PinmemberMaxowww29-Mar-13 4:02 
QuestionError Invalid credentials Pinmemberhemantrautela13-Oct-12 2:42 
Questionhow can i get applicationname? PinmemberMember 812652226-Sep-12 8:53 
GeneralReason for my vote of 4 I like it Pinmembercoded00720-Dec-11 22:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 24 Nov 2011
Article Copyright 2011 by Bangla Gopal Surya Prakash
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid