Introduction:
In this article I will explain how to import gmail contacts of a user by using GContacts Data API provided by Google.
Description:
We have developed one social network site at that time we think that how to popularize the our social network site I have checked some of social network sites at that time we got idea to implement import contacts concept is best to intimate all of our friends at a time I have searched so many websites to implement this concepts but no result finally I have implemented import contacts from gmail
I used ASP.NET and C# for developing this application.
We need to follow below steps to get gmail contacts
Step-1: Download Google data API setup from the specified URL
Or you can directly download with the following
That Set Up will installs set of Google Data dll’s (Google.GData.Apps.dll, Google.GData.Client.dll, Google.GData.Contacts.dll, Google.GData.Extensions.dll) into client installed Machine, you should collect that dll’s for your program.
Step-2: Design our aspx page (Default.aspx) by using with the following UI as simple scenario.
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>IMport Gmail Contacts</title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td> UserName</td> <td> <asp:TextBox ID="txtgmailusername" runat="server"></asp:TextBox> </td> </tr> <tr> <td> Password</td> <td> <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox> </td> </tr> <tr> <td> </td> <td> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </td> </tr> </table> </div> <div> <asp:GridView ID="gvmails" runat="server"></asp:GridView> </div> </form> </body> </html> |
Step-3: Add those downloaded google dll’s as reference to your website in visual studio->Solution Explorer ->Right Click-> Click on Add Reference….->Browse ->Get dll’s from Installed Location->Press OK.
Step-4:
A) Add namespace these namespace to your code behind
using Google.GData.Contacts; using Google.GData.Client; using Google.GData.Extensions; using Google.Contacts; |
B) After that write following code in code behind
public static DataSet GetGmailContacts(string App_Name, string Uname, string UPassword) { DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataColumn C2 = new DataColumn(); C2.DataType = Type.GetType("System.String"); C2.ColumnName = "EmailID"; dt.Columns.Add(C2); RequestSettings rs = new RequestSettings(App_Name, Uname, UPassword); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); Feed<Contact> f = cr.GetContacts(); foreach (Contact t in f.Entries) { foreach (EMail email in t.Emails) { DataRow dr1 = dt.NewRow(); dr1["EmailID"] = email.Address.ToString(); dt.Rows.Add(dr1); } } ds.Tables.Add(dt); return ds; } protected void Button1_Click(object sender, EventArgs e) { DataSet ds = GetGmailContacts("MyNetwork Web Application!", txtgmailusername.Text, txtpassword.Text); gvmails.DataSource = ds; gvmails.DataBind(); } |
Demo
Note:Keep Remember You Need Internet Connection @ the Time of Executing This Application.
I hope it helps you
Download sample code attached
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
64 comments :
But i am unable to call references for the dll(s) in class file.
However i have successfully did this in VS 4.0 but the same i can't do in VS 3.5.
Please suggest !
Hi Mantu
Please check the attached sample that is working in VS 3.5
Can u also post code for import contacts from Yahoo & Hotmail.
superb........
Please post code for import contacts from Yahoo & Facebook
its really superb suresh.thank u
i need AOL Contact import API Code
Can u please post the code for retrieving gmail contact profile pic.I have tried the codes in developer's guide but not able to get the pic.
It works like a charm. Keep up the good work! Thanks Suresh!
How to Change PassWord Character from .... to ****.
nice........
Please post code for import contacts from Yahoo & Facebook
hi,
that code was realy nice but there is some problem with that,
no one supposed that secure to enter her/his gmail ID.people used to opening a new page in Gmail domain to enter their IDs there.
Thnaks Buddy its Work Fine for me for gmail..thank you..agan
i need it for for hotmail and yahoo can you can you it it for me...
Very good post suresh. Can you tell me how you have code this demo part.
I have learnt many things from this site and this type of content is not available on other site.
Your articles are really Mind blowing...They help me great every times.I have also followed your Facebook Login. Your articles really fullfill my 98% requirements.
Thanks for posting your valuable resources..!!
please help me. how can i get application name?
Hi Bro
I did this fine.But i want to add s.no to this gridview as a column SNo. k it will be appeared but in the jump format like only even no's or odd no's
i'm using
==============================
DataColumn C1 = new DataColumn("SNo", typeof(int));
C1.ColumnName = "SNo";
dt.Columns.Add(C1);
C1.AutoIncrement = true;
C1.AutoIncrementSeed = 1;
C1.AutoIncrementStep = 1;
======================
pls send me how to add sno to the above grdvw.
Thanks in advance bro
Great job............very good artical
very gr8 job suresh..i really like it
very gr8 job suresh..i really like it
hi Suresh,
I got error that is Google.GData.Client.InvalidCredentialsException: Invalid credentials.
But i gave correct username password.
In local its working good.
What happen.?
hiii.. this example is very helpful for me for fecthing my gmail contact, but i also get my gmail profile information like my name, email,gender etc.. so how can i fecth this info in my application.. help me
hi Suresh, this example is very helpful for me for fetching my g-mail contact, I want to get online contact list from g-mail can you send me your suggestions and code to my mail-id kesavakumarv@gmail.com. Thanks in advance.
hi suresh...
can u post to import all latest email from inbox using gmail account.
Dear sir
I want to create an application like gtalk where automatical reply option is available for user
foreach (Contact t in f.Entries)
in this case i have error what shoiuld i do? i need ur answers guys.........
Hi Sir,
thank you very much. for this article.
hello,I am Sagar J
my all contacts are importing when i run my project on local host,but when i publish the web application on server it gives me error 'Invalid Credentials'
my code is as below--
//Provide Login Information
RequestSettings rsLoginInfo = new RequestSettings("http://demo.vishwainfosoft.com/TalentAcquisition/TA_Home.aspx", txtGEmail.Text, txtPassword.Text);
rsLoginInfo.AutoPaging = true;
// Fetch contacts and dislay them in ListBox
ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);
Feed feedContacts = cRequest.GetContacts();
try
{
foreach (Contact gmailAddresses in feedContacts.Entries)
{
Console.WriteLine("\t" + gmailAddresses.Title);
//lstContacts.Items.Add(gmailAddresses.Title);
//chklContacts.DataBind();
foreach (EMail emailId in gmailAddresses.Emails)
{
Console.WriteLine("\t" + emailId.Address);
//lstContacts.Items.Add(" " + emailId.Address);
chklContacts.Items.Add(emailId.Address);
ViewState["TCount"] = chklContacts.Items.Count;
foreach (ListItem item in chklContacts.Items)
item.Selected = true;
lblTotalContacts.Text = "Total" + " " + ViewState["TCount"].ToString() + " " + "records found...";
}
}
}
catch(Exception ex)
{
lblTotalContacts.Text = ex.Message;
}
chklContacts.DataBind();
Great Article.. I just tried it out and worked like a charm..
The only confusion I have is that, if contacts can be imported from gmail using the method you have shared, what is the benefit of using the Google Contact API via OAuth 2.0 and access tokens?
Would really appreciate if you could throw some light on this.
Thanks a lot.
Hi Suresh,
I have tried your code and it can extract gmail contacts successfully when it is running from local machine (India location) but when trying to upload server and trying to extract then gmail suspecting its suspicious attempt and blocking login.
Do you have any information how to solve this problem?
Thanks for writing so many codes for others.
Suman
Hi sir,I have tried ur code it is working fine but i want to extract the contacts of yahoo also.how it can be done?
Do you have any information regarding this problem?
Hi sir,I have tried ur code it is working fine but i want to extract the contacts of yahoo also.how it can be done?
Do you have any information regarding this problem?
Hi,
Can u provide the API for Yahoo and Hotmail also.
<a href="http://hotmail.com" target="_blank">Hotmail</a>
Hi Sir
This very good and awesome article
Can you write program like this for Invite Facebook and twitter and LinkedIn contracts?? and publish us please??
hiiiii... suresh
I want to show all mails into my own site, so any code for this probelm
helo
I want to store all gmail in dtabase.
any help?
Thanks In advance
How to import Facebook and MSN and yahoo contacts in c# using asp.net please sent me details in this id:emails4boopalan@gmail.com ,,i am awaiting bosss...
Very insightful idea. thanks.
I Have Security to My EmailId I can't Get Contacts now.It Shows Invalid Credentials
Great Articule, how I can get username and picture, not only de email? thanks
Good Job Suresh
work fine with there is not exists two step verification but give error
Google.GData.Client.InvalidCredentialsException: Invalid credentials
when user has enable two step verification service
Please provide me solution what i have to do when two step verification come in picture and how do i come to know user has active two step verification or not
PLEASE ANSWER TO ALL QUESTIONS ABOVE SURESH
thats good work dear but when im going to implement my project vs2010 that giving one error in foreach loop
showing error that : Email is a namespace but like used type . can u help me.
hi its great tutorial..nicew its works fine..but how can i check credentials values ..before
hai sir..i want to invite facebook friends for an event in to my website so plz help me
how to handle invalid credential exception using gdata while importing contacts in asp.net C#
hi sir,its not working its saying invalid credentials please can you tell me the issue
the code is not working anymore
google blocks it
nice.........its Work
How Can we get all Contact information from Gmail account using Email ID
Plz Help me Sir..
this is not working getting error message the error is google convert http to https
hi..
How can I download my contacts photo's with the help of this application. Can you please reply as early as possible.
Hello,
I have read all comment. There are many comment like "Invalid credentials".
But there is not answer for this issue.
Please call me if you have any solve
I am getting same error. I am sure i have enter correct username and password.
Hello,
Here attached code sample not working in VS 3.5 and 4.0
anyone getting solution so please suggest here...
Execution of authentication request returned unexpected result
Thank you for the information, I think this article is very useful for all who read it.
.
Execution of authentication request returned unexpected result: 404
Execution of authentication request returned unexpected result: 404
how can i solve this
how to get my email id list if my gmail is already logged in?
how to import Contacts from GMAIL using MVC4,Linq
"Execution of authentication request returned unexpected result: 404".I get the error in this line, foreach (Contact t in f.Entries)
Execution of authentication request returned unexpected result: 404
I am trying to run above code but its giving me below error please suggest
An exception of type 'Google.GData.Client.GDataRequestException' occurred in Google.GData.Client.dll but was not handled in user code
Additional information: Execution of authentication request returned unexpected result: 404
Note: Only a member of this blog may post a comment.