How to Fetch Gmail contact List From your gmail account

Hi Friends,

             Here I am posting  a code to fetch or get gmail contact in our application. For this we need to include some gmail APIs which required while in importing the contact list.
Before code we have to download APIs from HERE .After clicking on this you will get a page like this:

You should include following name spaces
using Google.GData.Client;
using Google.Contacts;
using Google.GData.Extensions;
using System.Collections.Generic;

Then you can use this method...

private List<string> GetContactList(string email, string pwd)
    {

        List<string> lstContacts = new List<string>();

        // Here required your gmail id and password.
        RequestSettings rsLoginInfo = new RequestSettings("", email, pwd);
        rsLoginInfo.AutoPaging = true;
        ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);

        // get 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);
            }
        }
        
        return lstContacts;      
    }

Hope this will help you ...
Regards,
Rajesh

0 comments: