Several times we need to develop web applications which require to import or fetch Gmail Contacts or address book.
In this example i'm explaining how to fetch or import Gmail contacts in Asp.net web applications using C# and ASP.NET.
For getting started we need to download Google Data API and install on the system to get the desired dlls.
Create a new website and visual studio and put these 3 dlls in BIN folder of application from the location google data API has been installed on ur system.
1. Google.GData.Client
2. Google.GData.Contacts
3. Google.GData.Extensions
Now add references to these dlls in ur application by right clicking on solution explorer and select add reference.
Login.aspx:
Login.aspx.cs
Welcome.aspx.cs
Note: If rs.AutoPaging=false then only first 25 contacts will be displyed from gmail. So to get all contacts from gmail it must be true.
I think this post will help you.
Thanks.
In this example i'm explaining how to fetch or import Gmail contacts in Asp.net web applications using C# and ASP.NET.
For getting started we need to download Google Data API and install on the system to get the desired dlls.
Create a new website and visual studio and put these 3 dlls in BIN folder of application from the location google data API has been installed on ur system.
1. Google.GData.Client
2. Google.GData.Contacts
3. Google.GData.Extensions
Now add references to these dlls in ur application by right clicking on solution explorer and select add reference.
Login.aspx:
<asp:ImageButton ID="btnGoogle" Text="Google" ImageUrl="gmail-icon.jpg.png" runat="server" ToolTip="Login to your gmail account and import your contacts." /> |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using Google.Contacts; using Google.GData.Client; using Google.GData.Contacts; using Google.GData.Extensions; public partial class Welcome : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { if (Request.QueryString["token"] != null) { string token = Request.QueryString["token"]; Session["token"] = AuthSubUtil.exchangeForSessionToken (token, null).ToString(); Response.Redirect("~/Welcome.aspx", true); } else { btnGoogle.PostBackUrl = AuthSubUtil.getRequestUrl(Request.Url.ToString(), "http://www.google.com/m8/feeds/", false, true); } } |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using Google.Contacts; using Google.GData.Client; using Google.GData.Contacts; using Google.GData.Extensions; public partial class Welcome : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["token"] != null) { RetrieveToken(); } } public void RetrieveToken() { GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("cp", "myapp"); string x = Convert.ToString(Session["token"]); RequestSettings rs = new RequestSettings("myapp", x); rs.AutoPaging = true; ContactsRequest cr = new ContactsRequest(rs); try { Feed<Google.Contacts.Contact> f = cr.GetContacts(); List<string> y = new List<string>(); foreach (Google.Contacts.Contact e in f.Entries) { foreach (EMail email in e.Emails) { y.Add(email.Address); } } } catch (GDataRequestException gdre) { } } |
I think this post will help you.
Thanks.
Hi sir,
ReplyDeleteHow to get user profile from gmail using Gmail API (or) using OAuth?
Please help me..!
Thanks in advance,
prapoorna.
HI,
DeleteIts better to use social Auth .net dll 2.0 version to get user Profile Details.it is a library where we can download contacts/Profile from various sources like- Gmail,Facebook, MSN,Yahoo, LinedIn etc. U can try the demo project which is attached at the url:
http://code.google.com/p/socialauth-net/
Thank you sir,
ReplyDeleteprapoorna
Hi sir,
ReplyDeleteCan u please give me the complete code for getting user profile from gmail using oauth? I have consumer key and secret but i didn't understand how to implement using C# to get userprofile. Please help me..!
Thanks in advance,
prapoorna.
you can download demo of getting profile from gmail from following url:
Deletehttp://code.google.com/p/socialauth-net/downloads/detail?name=SocialAuth-net-2.0beta.zip&can=2&q=
just download this demo and open in VS 2010 and
study it and modify it accordingly.
I want add / modify / delete google contacts with oauth in vs 2008
ReplyDeletehi all,
ReplyDeleteIt working fine and, very helpful to me
hi it is very helpful to me, its working fine
hi mr sitha ramaiah garu.
Deletei am also following an a same way but getting this error Execution of authentication request returned unexpected result: 404.please help me how can i overcome this..
i need Facebook and MSN and yahoo get Contact List using C#.NET/Asp.NET code
ReplyDeleteplease sent to in this emailid:emails4boopalan@gmail.com..i am awaiting for ur reply...
Hi i used this code and i got lot of errors plz tell me what to do...
ReplyDeletei am getting a null value in f.entriries
ReplyDeleteforeach (Google.Contacts.Contact e in f.Entries)
{
foreach (EMail email in e.Emails)
{
y.Add(email.Address);
}
}
Can you please help me and i need to show the contacts in a grid.
Execution of authentication request returned unexpected result: 404
ReplyDeletehow to overcome this error