Home Our Apps Contact Articles
Please Note: The 0.7 version of the Opensocial API rendered this object useless by making significant changes to the data API. The good news is that 0.7 functionality is much simpler, and won't require a getter/setter object such as this one. Tuesday, December 04, 2007

A Person App Data Getter/Setter Object.

Getting personAppData can be complicated using the standard opensocial API. This object simplifies it to one method call for setting and getting.

The personAppData object currently includes (2) methods:

  1. set(callBack, Person, Key, Data): Sets Person App Data.
    • CallBack: (Function) Fires after the update is complete.
    • Person: (String) the person to update data for (only 'VIEWER' is currently allowed).
    • Key: (String) what to name the data, you'll use this to retrieve it.
    • Data: (String) The data itself.
  2. get(callBack, Group, Key): Gets Person App Data
    • CallBack: (Function) the function to send the data result object to.
    • Group: (String) the person or group identifier. (one of 'VIEWER', 'OWNER', or 'OWNER_FRIENDS')
    • Key: (Array or String) the data key(s) to retrieve.

The personAppData.set method will return NO DATA. If an error occurs, it will use it's internal log function (which you should adjust) to print out an error and exit.

The personAppData.get method will return one Map object (which is sent to the callback function as an argument). The returned object contains all of the requested data in the following format:


         { 
            PersonId1:{
                    dataKey1:uniqueValue1
                    ,dataKey2:uniqueValue2
                    ,dataKey3:uniqueValue3
                    ,...
                  }
            ,PersonId2:{
                    dataKey1:uniqueValue1
                    ,dataKey2:uniqueValue2
                    ,dataKey3:uniqueValue3
                    ,...
                  }  
         }        
        

Here is an example of using this object to get and print some data:


            var dataKeys = [ 'dataKey1', 'key2' ];
            personAppData.get( myHandler , 'OWNER_FRIENDS' , dataKeys );  // one function call.. that's it
    
            function myDataHandler( returnedObject ){ 
                    // now I can access/iterate through the data 
                    var html = ''; 
                    for( var personId in returnedObject ){ 
                        html += 'Person Id: ' + personId + ' -- Data: ' + returnedObject[personId].myData + '<br /><br />'; // myData is the data key 
                    } 
                    document.body.innerHTML = html;
              }        
        

This object is the result of our Person App Data Tutorial, but is a fairly good start for any program needing to write or retrieve Person App Data. This file should be considered public domain.


To view the code, please use this link: http://www.iwiddit.com/article_xml/personAppData.html A working xml example can be found here: http://www.iwiddit.com/article_xml/personAppData.xml

[ Page Top ](c)2009 iWiddit.com - Privacy Policy - Feedback - SiteMap

iWiddit Logo iWiddit Opensocial Developers