Google Contacts Wrapper

This post is more than 2 years old.

Earlier today a user asked if I knew anything about reading Google contact information. I wasn't aware of an API for this, but turns out, one did exist (Contacts Data API). I think I'm finally getting used to the Google way of thinking when it comes to APIs (although see my PS at the bottom), so this one was rather easy to set up.

I just released the GoogleContacts project at RIAForge. This is a simple CFC that can retrieve both contacts and groups from your account. It doesn't support writing back to the system yet. Nor does it support dynamic data. (Google lets you put arbitrary name/value pairs into a contact, which is kind of nice.)

p.s. For folks who use my YouTube wrapper, the engineers on the YT team changed something on the back end that broke many people's implementation of the Upload API. A user reported the bug to me this week and I've been working on fixing it, but it's rather low level so it may be a few more days before it is fixed.

From what I know - this change wasn't announced. When I looked on the forums I saw a bunch of messages from folks wondering why various libraries stopped working all of a sudden. If you manage an API, I really think you have to go out of your way to manage changes, even simple changes, to ensure you don't leave your customers hanging. From what I know, their change was to essentially get a bit more strict, so in theory the change should not have broken any client. Still though, perhaps a bit more warning would have been nice!

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Sam Clement posted on 9/11/2008 at 5:53 AM

Nice stuff, Ray. I've been playing around with the wrapper and it works really well. The only thing I noticed was that it didn't work with 'Google apps for my domain'. To get it to work I just added another cfhttpparam (name="accountType" value="HOSTED_OR_GOOGLE") to the cfhttp call in the getAuthCode method on the base.cfc component. Hope that helps someone.

Comment 2 by Raymond Camden posted on 9/11/2008 at 6:03 AM

Can you file a bug report for that please? I'm going to be applying base.cfc to my Calendar code as well.

Comment 3 by Nando posted on 10/26/2008 at 10:02 PM

I've been working to extend the component to add a contact. A few details might help someone else.

First, it took a little fiddling to figure out the correct format to send the http request. Here's what I came up with:

<cfhttp url="#addContactUrl#" method="post" result="result">
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#variables.authcode#">
<cfhttpparam type="header" name="Content-Type" value="application/atom+xml">
<cfhttpparam type="body" value="#entry#">
</cfhttp>

Second, if you want to add a contact to a group immediately, you need to add the namespace definition for gContact to the entry tag, like so:

<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g... xmlns:gContact='http://schemas.google.com/c...

Nando

Comment 4 by Raymond Camden posted on 10/27/2008 at 7:34 AM

Nando, do you want to add this to the project?

Comment 5 by A Newbie posted on 1/7/2009 at 1:44 AM

Thanks for the Google contacts. But, honestly, I have no clue what to do with the information retrieved. There are too many structures inside arrays inside structures. If you kindly could show us newbies the way. Thanks.

Comment 6 by Raymond Camden posted on 1/7/2009 at 4:24 AM

Well, to be honest, all my code does is get you the contacts. How you use it is up to you. Let's say you were building a new social networking site for zombies (DeadLikeMe). You could ask your users to provide Google username and password info, fetch their contacts, and then say, "Hey, shall I email these guys and invite them to join you on our site?"

As for how to use the data itself - yes, it is a large array of structures - but that just represents all the contact info we have. Addresses, phone numbers, etc. Each structure key should be properly labeled though.

Comment 7 by A Newbie posted on 1/7/2009 at 12:16 PM

Thanks for the reply Ray. I really meant just how do I loop over all structures and arrays and save the extracted data in a database. Or just display in a table in a web page. I am really trying to learn to do both. Regards.

Comment 8 by Raymond Camden posted on 1/7/2009 at 5:43 PM

Oh, for that, I'm going to simply suggest reading the CFML Reference, specifically the struct and array functions. There aren't many, but you will learn when functions are provided to loop over/use structs and arrays.

Comment 9 by Micah posted on 4/7/2009 at 4:29 AM

Any progress with the Add/Edit/Delete features?

Thanks.

Comment 10 by Raymond Camden posted on 4/7/2009 at 5:24 AM

Zip. Always open to submissions on it.