Saturday, June 26, 2010

The Google Buzz API

It's been a month Google released their Buzz API at Google I/O and I have been dying ever since to write an article on it. Finally got an opportunity today and really hope that the posts live up to my expectation :)

In this post, I am going to introduce the Google Buzz API and the technologies surrounding it like OAuth, REST, AtomPub and JSON. And in my next post, I will be emphasizing on how to integrate OACurl, an OAuth wrapper, with a simple Java Desktop Application. Most of the information in this post is pretty basic and if you are comfortable with these technologies, I would recommend you to skip the post.

Google Buzz

Google Buzz is a social networking and messaging tool from Google, designed to be integrated into Gmail. Google Buzz was an attempt by Google to compete with micro-blogging services like Twitter. After the release of the Buzz API, it has been well received both as a platform and as a service.

The Google Buzz API revolves around two main concepts - Authentication which is done through Open Authorization (OAuth) and Service Usage which is managed using the REST architecture with data formats like XML (through AtomPub) and JSON.

Authentication

OAuth is an open standard that allows users to share their private resources like photos, videos, etc. stored on one site with another site without having to hand out their username and password. It works through the exchange of tokens which provides access to a specific site for specific resources for a defined duration.

Most of Google Data APIs like the Google Calendar Data API, Blogger Data API, Google Contacts Data API, etc. use OAuth for authentication. The authentication process is done through a Web Browser for web applications as well as desktop applications using the APIs. A browser pops up and users are authenticated with respect to their usernames and passwords directly by Google and then the control is returned back to the application which can proceed accordingly.

A major disadvantage of this process is that a web-browser should be available for authentication even for desktop applications.

Service Usage

Data transfer for the Buzz API is done primarily on the basis of REST (Representational State Transfer). It is a style of software architecture for distributed hypermedia systems such as the World Wide Web. The crux of REST is that is uses the basic HTTP methods like GET, POST, etc. for resource manipulation (getting a resource, saving a resource, etc.)

Google Buzz API returns data in two formats - XML and JSON. XML is sent in the form of AtomPub. AtomPub (also known as APP) stands for Atom Publishing Protocol. It is a HTTP-based protocol for creating and updating web resources. It uses an XML language known as the "Atom Syndication Format" (ASF) and is very popular for web feeds. The Atom Syndication Format and AtomPub form the Atom Standard. The ASF is primarily an XML format with tags like feeds, links, etc.

Google Buzz API can also return back data in the form of JSON. JSON, standing for JavaScript Object Notation, is an open standard designed for human-readable interchange. Despite its strong relationship to JavaScript, it is language-independent with parsers available for almost every language.

The major reason for Google Buzz API to offer JSON besides ATOM was that JSON parsing is comparatively faster than XML parsing in JavaScript. So in web applications which might pull data from the Google Buzz API using JavaScript and AJAX, JSON parsing will be a major performance gain.

A Quick Example

Navigate to https://www.googleapis.com/buzz/v1/activities/userId/@public to see your latest public buzzes in the ATOM format and to https://www.googleapis.com/buzz/v1/activities/userId/@public?alt=json to see them in the JSON format.

There are several URLs like these available at the Google Buzz API site - http://code.google.com/apis/buzz/v1/using_rest.html. However most of them require authentication before they show the results, which means that without authorization by OAuth, a URL based mechanism will not fetch the data.

To know your userId, you can do the following steps -

  • Login to GMail and go to the Buzz tab
  • Click on your name which is displayed at the upper-left corner of the Buzz tab
  • The last handle (the string after the last /) is your userId

2 comments:

Abhishek said...

Hi Gautum,

Nice post. I am making a Google Buzz Desktop Client. I am able to get all the posts for a user's consumption feed using Oauth but i have run into a problem. When the feed contains a private post all I get is title saying "Private post only viewable at LONG URL". I am unable to get this post by sending a request to LONG URL. How do I get that post?

Unknown said...

Hi Abhishek!

To be honest, I have never tried using OAuth directly in a desktop application. I have been delegating that to OACurl in my applications.

I have tried consuming private feeds using OACurl after your comment and it seems to be working properly. Check if the authentication process is working as expected. In case the problem still persists, I would recommend you to go through the source code of OACurl as it achieves something similar.