100 likes | 201 Views
Introduction to opensocial-actionscript-client. Sung Wu Aaron Tong 2009/03/20. Agenda. Intro Architecture Code-sample Resource. A Flex library for accessing OpenSocial API OpenSocial 0.81 AS3 Opensource. http://code.google.com/p/opensocial-actionsctip-client. Introduction.
E N D
Introduction to opensocial-actionscript-client Sung Wu Aaron Tong 2009/03/20
Agenda • Intro • Architecture • Code-sample • Resource
A Flex library for accessing OpenSocial API OpenSocial 0.81 AS3 Opensource http://code.google.com/p/opensocial-actionsctip-client Introduction
Architecture OpenSocial Container Browser OpenSocial Gadget Dynamically Generated javascript Your swf Javascript API
Design Decisions • Uses OpenSocial Javascript API instead of OpenSocial REST spec • Crossdomain.xml restrictions on some containers • REST not implemented yet on some containers • Dynamic Javascript injection • Simple deployment • Interface: follows OpenSocial Javascript API • Easy to understand if you come from the normal OpenSocial development world. Follows the standard.
Initialization <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> …. private function init():void { //create the Container container = Container.instance; container.setContainer(new StandardContainer()); }
Code sample: update data private function updateData():void{ var dr:DataRequest = container.newDataRequest(); dr.add(dr.newUpdatePersonAppDataRequest("VIEWER", "testdatakey1", 'test')); dr.send(updatePersonAppDataCallback);}private function updatePersonAppDataCallback(dataResp:DataResponse):void { Alert.show("updatePersonAppDataCallback(). \n dataResp.hadError()=" + dataResp.hadError() + "\n dataResp.getErrorMessage()=" + dataResp.getErrorMessage());}
Code Sample: fetch data private function fetchData():void{ var dr:DataRequest = container.newDataRequest(); var idSpecParam:Object = {}; idSpecParam[com.nextgenapp.opensocial.IdSpec.Field.USER_ID] = "VIEWER"; var idSpec:IdSpec = container.newIdSpec(idSpecParam); dr.add(dr.newFetchPersonAppDataRequest(idSpec, ["testdatakey1"], null), opt_key); dr.send(fetchPersonAppDataCallback); }private function fetchPersonAppDataCallback(dataResp:DataResponse):void { if (dataResp.hadError()) { Alert.show("error: " + dataResp.getErrorMessage()); } var appData:Object = dataResp.get("data").getData(); Alert.show("appData=" + appData); // appData should have a member (user's id). inside that, it should have a member var appDataDisplay:String = ""; for (var propNameLevel1:String in appData) { appDataDisplay += ("\n" + propNameLevel1 + " : " + appData[propNameLevel1]); for (var propNameLevel2:String in appData[propNameLevel1]) { appDataDisplay += ("\n----" + propNameLevel2 + " : " + appData[propNameLevel1][propNameLevel2]); } } Alert.show("appData expanded=" + appDataDisplay);}
Resource • Project site: http://code.google.com/p/opensocial-actionscript-client • Blog: http://opensocial-actionscript-client.blogspot.com • Group: http://groups.google.com/group/opensocial-actionscript-client • Contact: Sung Wu apiswswsw@gmail.com
Status • Several major API functions are implemented. Still under development to cover all API functions