//Instructions: You need the Google Contacts Data API located at http://code.google.com/p/google-gdata/downloads/list //Follow the directions for setting up the API for use in Visual Studio located here: http://code.google.com/apis/gdata/articles/dotnet_client_lib.html //Provide the name of your application, your Gmail address and Gmail password to the method for retrieving your contacts //Import the following Namespace(s): //System.Collections.Generic //Google.GData.Client //Google.Contacts //Google.GData.Extensions //Google.GData.Contacts //First, a small class to hold the data ////// class to hold the data from our Google contacts /// public class GoogleContacts { public string title { get; set; } public string email { get; set; } public string im { get; set; } } //Next method for retrieving the contacts ////// method for retrieving all contacts in a persons Google Mail address book /// /// the application making the request/// username of the account/// password of the account///public static List GetGoogleContacts(string appName, string un, string pwd) { //list to hold all contacts returned List contactList = new List (); //create an instance of the request settings RequestSettings settings = new RequestSettings(appName, un, pwd); //set AutoPaging to true so we get all the contacts settings.AutoPaging = true; //now send ouor request for contacts ContactsRequest request = new ContactsRequest(settings); //retrieve the contacts returned Feed feed = request.GetContacts(); //here we will loop through all the contacts returned and add them to our list foreach (Contact contact in feed.Entries) { GoogleContacts c = new GoogleContacts(); c.title = string.IsNullOrEmpty(contact.Title) ? "Name Not Present" : contact.Title; c.email = contact.Emails[0].Address; c.im = contact.IMs.Count == 0 ? "IM Address Not Present" : contact.IMs[0].Address; contactList.Add(c); } return contactList; } //Sample usage static void Main(string[] args) { List list = GetGoogleContacts("GoogleTest", "YourGmailAddress", "YourGmailPassword"); Console.WriteLine("Total Contacts Retrieved: " + list.Count()); Console.WriteLine("************************************************"); Console.WriteLine(); foreach (GoogleContacts contact in list) { Console.WriteLine(contact.title); Console.WriteLine(contact.email); Console.WriteLine(contact.im); Console.WriteLine(); } Console.ReadLine(); }
Взято с http://www.dreamincode.net
0.00 (0%) 0 votes








