How to retrive the Contact from gmail using Google API in Asp.Net?

Hemanthlaxmi
Posted by Hemanthlaxmi under ASP.NET category on | Points: 40 | Views : 7875
What are the Google Contacts APIs?

The Google Contacts APIs allow client applications and other data consumers to request Google Contacts content.

If read-only access is sufficient for your needs, then consider using the Portable Contacts API. If you need write access to Google Contacts, then use the Data API. The two APIs supply the same information in different formats.
Google Contacts Data API

The Google Contacts Data API allows client applications to view and update Contacts content in the form of Google Data API feeds. Your client application can request a list of a user's contacts, edit or delete content in an existing contact, and query the content in an existing contact.

Here are some of the things you can do with the Contacts Data API:

Synchronize Google contacts with contacts on a mobile device
Maintain relationships between people in social applications
Give users the ability to communicate directly with their friends from external applications using phone, email, and IM

Portable Contacts API (Labs)

The Portable Contacts standard allows a client application to retrieve a user's lists of contacts from a variety of web services.

Google's implementation of Portable Contacts lets your web application request data from Google Contacts, in standard Portable Contacts format.

For simple application you need to add the Following DLL in your website
http://code.google.com/apis/contacts/docs/3.0/developers_guide_dotnet.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Contacts;
using Google.Contacts;
using System.Data;

public partial class GoogleAPI_CONTACTS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RequestSettings rs = new RequestSettings("Application Name", "abcd@gmail.com", "**********");
ContactsRequest cr = new ContactsRequest(rs);//Request All Contacts
rs.AutoPaging = true;
Feed<Contact> f = cr.GetContacts();
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Name");
dt.Columns.Add("Home Emails");
dt.Columns.Add("Work Mails");
dt.Columns.Add("Other Mails");
dt.Columns.Add("Work Phone");
dt.Columns.Add("Other");
foreach (Contact contact in f.Entries)
{
dr = dt.NewRow();
Name n = contact.Name;
dr[0] = n.FullName;
string homeEmail = String.Empty;
string workEmail = String.Empty;
string otherEmail = String.Empty;
string homePhone = String.Empty;
string workPhone = String.Empty;
string otherPhone = String.Empty;
foreach (EMail email in contact.Emails)
{
if (email.Home == true)
{
if (homeEmail.Equals(""))
{
homeEmail += email.Address;
}
else
{
homeEmail += ",";
homeEmail += email.Address;
}
}
if (email.Work == true)
{
if (workEmail.Equals(""))
{
workEmail += email.Address;
}
else
{
workEmail += ",";
workEmail += email.Address;
}
}
else
{
if (otherEmail.Equals(""))
{
otherEmail += email.Address;
}
else
{
otherEmail += ",";
otherEmail += email.Address;
}
}
dr[1] = homeEmail;
dr[2] = workEmail;
dr[3] = otherEmail;
}
dt.Rows.Add(dr);


gv1.DataSource = dt;
gv1.DataBind();
}
}
}

<div>
<asp:GridView ID="gv1" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
</div>

Comments or Responses

Login to post response