Friday, 7 June 2013

OSAPI on iGoogle

The OpenSocial 0.9 blueprint alien a simpler API alleged OS Lite (also accepted as OSAPI) which uses a syntax that's friendlier for Javascript developers. 

Some barbarous eyed developers accept already noticed that iGoogle works with a lot of OpenSocial 0.9 features. The accomplishing of OSAPI should plan as accurate at 

Here's a basal archetype to play with so you can get started with the OS Lite API. In this archetype we will assassinate a appeal to back and affectation a account of the user's friends.

 <ModulePrefs height="800" title="osapi friends" title_url="">
  <Require feature="opensocial-0.9" />  <Require feature="osapi" /> <Content type="html" view="home">  <![CDATA[  <script>   var result = '';
    osapi.people.get({userId:'@owner', groupId:'@friends'}).execute(function(response) {
    result += 'You have ' + response.list.length + ' friends:<ul>';    for (item in response.list) {     result += '<li>' + response.list[item]';    }    document.getElementById("output").innerHTML = result + '</ul>';   });  ]]> </Content>

To keep it short we've omitted detailed error handling in our example. It should be pretty clear what the script is doing but it's good to check response.error and gracefully handle problems.
The first call, osapi.people.get({userId: '@owner', groupId: '@friends'}) constructs a request object to get a list of people for the current user from their friends group. The call to execute will make a call to the service, passing the results to a callback function. Our callback is a simple anonymous function that across the result set.
When running the code, look at the JSON response from iGoogle and you'll see that the data structure is pretty straightforward. Use some of the tools built into your browser such as:
  • Firebug if you are using Firefox
  • Chrome or Safari Developer tools.
  • Opera Dragonfly
  • Internet Explorer 8's debugger

These accoutrement advice alter your Javascript but aswell can appearance you the HTTP letters that are traveling to iGoogle from your apparatus and the responses iGoogle sends back. There's aswell the OpenSocial Developer App which is a apparatus that will body approximate letters that you can absorb in analysis code. 

As we get added OpenSocial 0.9 activated out on iGoogle, we'll amend the affidavit to reflect the accepted functionality.

If you like OSAPI and you're going to be at Google I/O 2010, you can find us in the Hack Alcove on May 20 2010 from 2-3:30pm. We'll give a walk through of a gadget built with osapi for iGoogle gadget developers. There's also a talk for iGoogle developers at I/O on May 20 2010 at 10:15am.