Storing application data on the OpenSocial host is a great way to offload some unnecessary database and application server load. Why request a preference such as a skin for a user profile from your servers if we can just let the container handle it? MySpace allows for ~1K of data storage per user per application. However, there is a bug with the method newFetchPersonAppDataRequest when added as the only item of a DataRequest. Calling send on the request doesn’t actually do anything! It returns a DataResponse object with no data. As a work around, grab some other information to ensure that the request actually is sent to the container’s server. I used the owner data in this example.
View Code JAVASCRIPT
// The function to load the application data function getAppData(){ var req = opensocial.newDataRequest(); var owner = opensocial.newIdSpec({"userId":"OWNER"}); req.add(req.newFetchPersonRequest(owner), "owner"); req.add(req.newFetchPersonAppDataRequest(owner, "appdata"), "owner_appdata"); req.send(getAppDataCallback); return; } // The callback for getAppData() function getAppDataCallback(d){ var owner = d.get("owner"); // if you need it, use it! var data = d.get("owner_appdata"); if(data.hadError()){ // handle the error appropriately return; } // do whatever your program needs to do with the data } |