AndyJarrett

Gmail Contacts Data API access with ColdFusion

I've been looking at accessing the Gmail contact data via their API. This is the first draft of my findings and is no way the finished solution but it does what it says on the tin and returns the email address's from a users Gmail account contacts. Its actually quite simple to and we're going to do this in 2 CFM pages.We are going to be using the AuthSub method of registration
There are three levels of registration:
  1. Unregistered: Application is not recognized by Google. The Access Request page, which prompts your users to either grant or deny access for your application, displays this caution highlighted in yellow: "Non-registered, not secure. This website has not registered with Google. We recommend that you continue the process only if you trust this destination."
  2. Registered: Application is recognized by Google. The Access Request page displays this caution: "Registered, not secure. This website is registered with Google to make authorization requests, but has not been configured to send requests securely. We recommend you continue if you trust this destination."
  3. Registered with enhanced security: Registered applications with a security certificate on file can use secure tokens. The Access Request page displays this message: "Registered, secure. This website is registered with Google to make authorization requests."

As we are going to be using the first method of Unregistered the user will getting some simple/basic prompts:

  1. The first will be asking them to log in and letting them know that "A third party service is requesting permission to access your Google Account"
  2. Second an Access Request page which lets the user know WHAT we are doing

Once they have logged in and agreed Google will take you back to your site. The

I've put the index.cfm in a folder on the root called contacts. Below is the content for index.cfm read the comments for what each variable is doing. This is all taken from Googles API docs on AuthSub proxy authentication.

#res.filecontent#

Our second page is getAddresses.cfm In the contacts folder

In my example I am only returning 25 records (for speed mainly) but if you want to know more about returning records check out Google API docs on query params. Also in my example I just dump the records. If you want to get out the email addresses you can use the following snippet.

#myxmldoc['feed']['entry'][i]['gd:email'].xmlAttributes.address#

There is still some work to do here but this is the bare bones and a starting point for anyone interested.