Adobe Solution Partner

January 25, 2008

Google API: Logging in with AuthSub Part 2

Filed under: ColdFusion, Google — Tags: , , , — Steve Nelson @ 8:39 am

The first step of the AuthSub proxy process is very simple. Which is good. It’ll ease you into using the Google API. Below is the first function in my GoogleAuthenticate.cfc file. I’ll publish the full file after I cover the individual functions. Feel free to build the CFC and follow along. Basically all you need to do is start with a file called GoogleAuthenticate.cfc, throw in some cfcomponent tags, then add the functions as I post them.

<cffunction name="AuthSubRequest"  returnType="void" >
    <cfargument name="next" type="string">
    <cfargument name="scope" type="string">
    <cfargument name="secure" type="string">
    <cfargument name="session" type="string">
    <cflocation url=" https://www.google.com/accounts/AuthSubRequest?next=#urlencodedformat(arguments.next)#&scope=#urlencodedformat(arguments.scope)#&session=#iif(arguments.session,1,0)#&secure=#iif(arguments.secure,1,0)#" addtoken="No">
</cffunction>

In a nutshell it is one line of code. It’s a cflocation. The two arguments to pay attention to are next and scope.

Next is the URL that Google will send the user back to after they login to google.com and accept your request to access their Google data. When you make use of this API you’ll need to have the next attribute point to one of your own CFM page. Something like: http://www.yourdomain.com/whatever.cfm then in that whatever.cfm file you you need to save the #url.token# variable that Google returns to you.

Scope is a little simpler. Basically if tells Google which part of the API you want to access. I get the feeling there are LOT of ’scopes’ (or eventually there will be a lot) but I have only found 3 so far:

1) http://spreadsheets.google.com/feeds

2) http://www.google.com/calendar/feeds

3) http://picasaweb.google.com/data/feed/api/user/victor.coustenoble?kind=album

I have tried the calendar and spreadsheet and it works great. I haven’t tried the picasaweb (photo uploads)

Secure is either 1 or 0 I haven’t even played with secure tokens. If anyone reading this has, explain the difference.

Session is also either 1 or 0 I’ve been setting session=1 because it allows you to save the token in a database and automatically log them back in later. It’s a little more complex. In a nutshell you take this token, and get ANOTHER token called a subsession token. I’ll explain that in another post.

So if you put this code into a file called: GoogleAuthenticate.cfc with cfcomponent tags. Here’s an example in action:

<cfinvoke component="GoogleAuthenticate" method="AuthSubRequest">
    <cfinvokeargument name="next" value="http://127.0.0.1/next.cfm">
    <cfinvokeargument name="scope" value="http://spreadsheets.google.com/feeds">
    <cfinvokeargument name="secure" value="0">
    <cfinvokeargument name="session" value="1">
</cfinvoke>

Easy enough huh? I can’t believe I just wrote a whole blog about one line of code (the cflocation). hahaha! beat that.

-Steve Nelson

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Technorati
  • TwitThis

2 Comments »

  1. Just thought you might want to know that a year later this series of posts have helped me a ton on my project.

    Many thanks for posting them.

    Comment by A Different Steve — January 16, 2009 @ 12:00 am

  2. It is a very help me

    Comment by Cofein — February 10, 2009 @ 12:00 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

 

Server Down?

Maximize Web application uptime by drawing upon Webapper's years of experience tuning and stabilizing many of the world's largest ColdFusion Web applications. Contact us today!