Click here to Skip to main content
Licence CPOL
First Posted 10 Dec 2011
Views 3,885
Bookmarked 7 times

Using Google data API to retrieve your contacts

By | 12 Dec 2011 | Technical Blog
Using Google data API to retrieve your contacts
A Technical Blog article. View original blog here.[^]

It is easy to interface the Google data API by using the library Google supply, for .NET too. Let’s have an example of acceding the contacts information:  

public class ContactFetcher
    {
       
        public event EventHandler<ContactFetchEventArgs> ContactFetch = delegate { };
        public void BeginFetchAll(string user, string password)
        {
            ContactsService svc = new ContactsService("MyApp");
            
            svc.setUserCredentials(user, password);
            
            List<ContactEntry> contacts = new List<ContactEntry>();
            int i = 0;

            svc.AsyncOperationCompleted += (s, e) =>
                {
                    foreach (ContactEntry entry in (e.Feed as ContactsFeed).Entries)
                    {
                        ContactFetch(this, new ContactFetchEventArgs
                        { Contact=entry, Current=++i,Of=e.Feed.TotalResults });
                    }
                    if (e.Feed.NextChunk != null)
                    {
                        svc.QueryFeedAync(new Uri(e.Feed.NextChunk), DateTime.MinValue, this);
                    }
                };
            svc.QueryFeedAync(new Uri(ContactsQuery.CreateContactsUri(user)), DateTime.MinValue, this);
        }
      
    }
    public class ContactFetchEventArgs:EventArgs
    {
        public ContactEntry Contact { get; set; }
        public int Current { get; set; }
        public int Of { get; set; }
    }

 

This class requires the following references:

  • Google.GData.Client
  • Google.GData.Contacts
  • Google.GData.Extensions

All these are available in precompiled form after installing the Google Data API setup. Of course, the complete API contains a method to interact with a lot of good things in addition:

  • Blogger
  • Calendar
  • Calendar Resource
  • Code Search
  • Contacts
  • Content API for Shopping
  • Documents List
  • Email Audit
  • Email Settings
  • Google Analytics
  • Google Apps Provisioning
  • Google Health
  • Google Webmaster Tools
  • Notebook
  • Picasa Web Albums
  • Spreadsheets
  • YouTube

The only missing point: there is no (not yet) a version for WP7, and the current codebase is not easy to port. Another missing point is that the API does not support OAuth2, that is indeed supported by the Google platform itself.


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Felice Pollano



Italy Italy

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmemberjibedoubleve1:24 11 Dec '11  
GeneralRe: My vote of 1 PinmemberFelice Pollano5:59 12 Dec '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 12 Dec 2011
Article Copyright 2011 by Felice Pollano
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid