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!
Archived Comments
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.
Can you file a bug report for that please? I'm going to be applying base.cfc to my Calendar code as well.
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
Nando, do you want to add this to the project?
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.
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.
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.
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.
Any progress with the Add/Edit/Delete features?
Thanks.
Zip. Always open to submissions on it.