Google+ API Released

Today Google+ released their “API” - Google+ Platform. I put that in quotes because their API now is only three methods, but it’s a start at least. The API allows you to get a user profile, get a user’s post stream, and fetch one particular post (what they call activities). OAuth is supported, but you can fetch public data as long as you get an API key. Since the results are all in JSON, using the API is disappointingly trivial. (Heh, ok, so I’m being sarcastic.) Here’s an incredibly trivial example using my person ID.

<cfset userid = "115106614688778962135"> <cfset key = "allyourbasearebelongtoadobe"> <cfif not structKeyExists(application, "userprofile")> <cfhttp url="https://www.googleapis.com/plus/v1/people/#userid#?key=#key#"> <cfset dataString = cfhttp.fileContent.toString()> <cfset data = deserializeJSON(dataString)> <cfset application.userprofile = data> <cfelse> <cfset data = application.userprofile> </cfif> <cfif not structKeyExists(application, "userstream")> <cfhttp url="https://www.googleapis.com/plus/v1/people/#userid#/activities/public?key=#key#"> <cfset dataString = cfhttp.fileContent.toString()> <cfset stream = deserializeJSON(dataString)> <cfset application.userstream = stream> <cfelse> <cfset stream = application.userstream> </cfif> <cfoutput> <a href="#data.url#"><img src="#data.image.url#?sz=100" align="left" border="0"></a> <a href="#data.url#">#data.displayName#</a> <cfif len(data.tagline)> <br/> <i>"#data.tagline#"</i> </cfif> <br clear="left"> <cfloop index="post" array="#stream.items#"> <a href="#post.url#">#post.title#</a> (#post.updated#)<br/> </cfloop> </cfoutput>

Since JSON "just works" in ColdFusion, there really isn't much to say here. The result objects are very detailed (here is the spec for the person resource) and you can do quite a bit with it. One of the cool tricks, for example, is that the image profile URL can be resized on the fly. Notice the sz attribute on the URL? That handles resizing it automatically. Here's how this little template rendered:

The activities listed above are only my public ones. But you could take my code above to easily generate a "badge" on your home page with your latest public posts (which is what you would want to share publicly anyway). I assume the API will be expanded soon. I'd love to see them create a way to embed profile pictures via an email address, much like a Gravatar service.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

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

Comments