Import Gmail Contacts Using C#

Posted: July 25, 2012 in ASP.net, C#, Uncategorized
Tags: , ,

In Many Sites We Can See There Are Options Of Importing Contacts From Gmail,Yahoo,AOL, Msn ..To Invite Friends To Join your website Or Something Like That..

Importing Gmail Contacts Is Not A Real Big Task . Google Has Provided Few dll`s Through Which You Can Import Gmail Contacts ..

Step 1 :  Download Google data API setup from the specified URL :

Step 2: Add These dll`s into Your Bin Folder ..
1.Google.GData.Apps.dll
2.Google.GData.Client.dll
3.Google.GData.Contacts.dll
4.Google.GData.Extensions.dll

Step 3 :Add These Namespace To Your Codebehind.
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.Contacts;

Step 4 : Add This Function Into Your 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;

}

By This Function You Can import Your Gmail Contacts . Your Contacts Will Be Saved In Dataset..You Can Bind that Dataset To Your .aspx File.

You Can Call This Method Like :

DataSet ds = GetGmailContacts(“Web Application!”, “UserName”, “Password”);

Hope This Post Will Help you Somehow . . :)

Waiting For Your Valuable Feedback.

Advertisements
Comments
  1. You really make it seem really easy together with your presentation but I to find this matter to be actually one thing that I believe I would by no means understand. It sort of feels too complicated and very large for me. I am taking a look ahead for your subsequent put up, I’ll try to get the hang of it!

  2. Thanks For Your Feedback .I Will Try To Explain Each Step From Now Onward 🙂 ..

  3. Its such as you learn my mind! You seem to grasp so much approximately this, such as you wrote the guide in it or something. I think that you can do with some percent to pressure the message house a little bit, however instead of that, that is wonderful blog. An excellent read. I’ll definitely be back.

  4. Kyle Dalere says:

    Great site! I truly like how it really is easy about my best sight and also the facts are actually well crafted. Positive questioning generate profits may be warned if a fresh article is actually designed. You will find activated to your Rss feed which have to accomplish the same goal! Have a pleasant time!

  5. Pinku says:

    *good* 😛

  6. Steven Olson says:

    I like this post, enjoyed this one thanks for posting .

  7. Vasudev says:

    Please if somebody can suggest a site where I can have a Java code to import GMAIL contacts list…
    Any help would be highly appreciated..

    regards

  8. Projects says:

    Thanks for share this incredible article with us is very interesting and provides valuable information that could be helpful for many people.

  9. So have you been attempting to say in the conclusion?

  10. I’d like to thank you for the efforts you’ve put in writing this blog.
    I really hope to view the same high-grade blog posts by you later on as well.
    In fact, your creative writing abilities has inspired me to get my own, personal website now
    😉

  11. pepper says:

    What’s Happening i am new to this, I stumbled upon this I’ve found
    It positively useful and it has helped me out loads. I hope
    to give a contribution & help different customers like its aided me.
    Great job.

  12. Lan says:

    Hi, just wanted to mention, I loved this post. It was funny.
    Keep on posting!

  13. seo says:

    Hello everyone, it’s my first pay a quick visit at this web page, and post is actually fruitful in favor of me, keep up posting these types of articles.

  14. We stumbled over here different website and thought I might as well check things out.
    I like what I see so i am just following you. Look forward to looking
    into your web page repeatedly.

  15. Mayan fake says:

    Hi there, this weekend is pleasant for me, because this time i am reading this impressive educational piece of writing here at my house.

  16. Maura says:

    My spouse and I stumbled over here from a different page and thought I might check things out.
    I like what I see so now i’m following you. Look forward to looking into your web page repeatedly.

  17. Suman Biswas says:

    Hi,
    I am following the same way and my code can extract contacts from gmail when running from local host but when trying from hosted server (in different country) then it is throwing a mail to user gmail with subject “Suspicious sign in prevented”. It seems somehow need to add my website to google;s trust list.
    Can you please help me on that to solve the issue?

    Thanks
    Sumab

  18. Thankyou for your reply.
    I can see in that webste there has some sample for Yahoo and MSN these are based on oAuth techniques. I know google also support this, can any one share this code for gmail?

    Thank you in advance
    Suman

  19. Hi,
    Is there any code for oAuth 2 for gmail?

    Thanks
    Suman

  20. saul says:

    I wish u can add aspx files 😀 This is very useful actually do you have any solution for facebook and twitter linkedin contacts

  21. Hi, I have implemented same code for getting gmail contacts into my project. it works well at local environment but when i uploaded it on server it gives error as ‘Invalid Credentials’ even if credentials are correct. I have given dll reference properly. Please let me know what can be the issue? Thanks

  22. Jessica says:

    What’s Happening i am new to this, I stumbled upon this I’ve found It absolutely helpful and it has aided me out loads.
    I hope to give a contribution & assist different users
    like its helped me. Good job.

  23. any final solution with full source code sample working about it ? For create contact, find single contact, update contact (for example, photo) , delete contact

  24. Turgut says:

    Thanks thanks very thanks

  25. Michael says:

    Thank you very much for this post.But I get exception and I cant solve it, I will be appreciate if you could help me.

    In this row:
    foreach (Contact t in f.Entries)

    I get this exception:
    Execution of request returned unexpected result: http://www.google.com/m8/feeds/contacts/default/fullMovedPermanently

    Any idea why do I get and how to handle this exception?

  26. DS says:

    Something has changed with google…. I am now getting the same error as Michael

  27. DS says:

    The reason why is here… https://developers.google.com/google-apps/contacts/v3/http-update

    The code here needs to be updated to represent the HTTPS update… Im fairly positive… Anyone know where to update the addresses?

  28. QoSi QuReshi says:

    Install-Package Google.GData.Contacts from your nuget pm your issue will be resolved

  29. Michael says:

    nice contribution and very helpfull… but is there a way to encrypt the password? i need to do a function where the username and password most remaind on the code, cuz any assistent must be able import contacts…. any idea of what kind of encryption gmail has and how to send the password encrypted?

  30. This code not working om live server plz suggest me..

  31. Здравствуйте, предлагаем Вам услуги комплексного продвижения вашего сайта, подробнее с нашими услугами Вы можете ознакомиться по ссылке http://www.anacron.ru/ Извините за беспокойство.

  32. This is a great tip particularly to those fresh to the blogosphere.
    Short but very accurate info… Many thanks for sharing
    this one. A must read article!

  33. karthi says:

    hi. i struggled last 2 days for this. i wrote the same code what you did. but got the error from yesterday that is “Execution of authentication request returned unexpected result:404 “.. what should i do now. can you help me.

  34. Mani says:

    Hi,

    By using the above code am getting only 25 contacts from my gmail. But i have more than 50 contacts. Please help

  35. Kiquenet says:

    Did you have latests version working in github ? maybe with unit test ?

    Are valid yet this assemblies?

    1.Google.GData.Apps.dll
    2.Google.GData.Client.dll
    3.Google.GData.Contacts.dll
    4.Google.GData.Extensions.dll

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s