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
- Download Google Data API Dlls
- Extract Google MSI component
- 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
- Create a new website
- Copy the below dll from above sample path & add below dll to your solution
- Google.GData.Client
- Google.GData.Contacts
- Google.GData.Extensions
- 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" />
- 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()
{
List<string> lstContacts = new List<string>();
RequestSettings rsLoginInfo = new RequestSettings("", "suryabg2000@gmail.com", "XXXXXX");
rsLoginInfo.AutoPaging = true;
ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);
Feed<contact> feedContacts = cRequest.GetContacts();
foreach (Contact gmailAddresses in feedContacts.Entries)
{
foreach (EMail emailId in gmailAddresses.Emails)
{
lstContacts.Add(emailId.Address);
}
}
GridView1.DataSource = lstContacts;
GridView1.DataBind();
}
Finally you will be able to see the data in the gridview
Happy Koooding… Hope this helps!