April 23, 2009

OpenSocial Spec 0.9 is published


Opensocial 0.9 spec is published on Apr 16 according to OpenSocial API blog (http://blog.opensocial.org/2009/04/opensocial-community-defines-version-09.html)
 
 
major features:
1. lightweight javascript API
2. proxied content  
3. data pipelining
4. templates and OSML
 

1. Lightweight javascript API will be a great news for developers.  I have blogged earlier about how cumbersome the JS API is.  Lightweight javascript API is a great improvement.  

eg.  examples coming from OpenSocial Release Notes:

Requesting the viewer in OpenSocial v0.8

var req = opensocial.newDataRequest(); req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER), "req"); req.send(callback); 

Requesting the viewer in OpenSocial v0.9

osapi.people.getViewer().execute(callback);

Once that Orkut and Myspace support lightweight javascript api in Spec 0.9.  I think we shall change our opensocial-actionscript-client interface to follow lightweight javascript api.  Right now, our interface mimics the regular javascript api in OpenSocial Spec 0.8.  

2. templates - people who are familiar with JSP EL will find this to be very similar.  This should make the code more readable.

3. OSML - each containers will be required to implement a set of standard tags such as Name Badge.  This is another timesaver.  


March 5, 2009

Dimension of app on myspace, orkut, and facebook


Each platform has different size limit for apps that appearing on their canvas and profile.  I hope this can be a collaborative effort, please feel free to chime in.  


Myspace
canvas: 960 x (no limit?)
narrow profile: 300 x ?
wide profile: 430 x ?

Reference: What is an Myspace app

orkut
canvas: 765x600
profile: 470x280

Reference: Anatomy of an orkut app


facebook
canvas: 760 x (no limit?)
main profile: ?
narrow profile: ?
wide profile: ?
application tab: ?

Reference:
You can see this in developer application.  When you create an application, it will ask you whether your canvas should be new size (760 px) or old size (68x px).

February 26, 2009

Create Activity feature added to the library


Updated Today (21 minutes ago)by swswsw
Labels:example
The library is capable of doing requestCreateActivity() now.

Example of requestCreateActivity

        private function createActivity():void {
               
var params:Object = {};
               
params[com.nextgenapp.opensocial.activity.Field.TITLE] = "test activitiy title";
               
var activity:Activity = container.newActivity(params);
               
                container
.requestCreateActivity(activity, com.nextgenapp.opensocial.CreateActivityPriority.HIGH, createActivityCallback);
       
}
       
private function createActivityCallback(respItem:ResponseItem):void
       
{
               
// note: requestSendMessage() returns ResponseItem, not DataResponse.  
                trace
("createActivityCallback");
               
Alert.show("createActivityCallback.  haderror=" + respItem.hadError());
               
if (respItem.hadError()) {
                       
// get the response item
                       
Alert.show("createActivityCallback.  errorCode=" + respItem.getErrorCode() + ".  errorMessage=" + respItem.getErrorMessage());
                       
                       
if ("forbidden" == respItem.getErrorCode()) {
                               
Alert.show("user denied permission.  you have to ask user for permission.");
                       
}
               
}
       
}

A full sample code can be found here: http://opensocial-tutorial-trial.googlecode.com/svn/trunk/os-as-lib-081-test/src/ActivityExampleOrkut.mxml

February 20, 2009

Examples for reading & writing appData

Example of update appData

    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());

}

Examples of fetch appData

        private function fetchData():void
{
var dr:DataRequest = container.newDataRequest();
//var idSpec:IdSpec = container.newIdSpec({ com.nextgenapp.opensocial.IdSpec.Field.USER_ID : "VIEWER"}); // does not work. has compile error.
//var idSpec:IdSpec = container.newIdSpec({ "USER_ID" : "VIEWER"}); // do this instead.
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
{
trace
("fetchPersonAppDataCallback()");
Alert.show("fetchPersonAppDataCallback()");
if (dataResp.hadError()) {
Alert.show("error: " + dataResp.getErrorMessage());
}

var appData:Object = dataResp.get(opt_key).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);
}

A full sample code can be found here: http://opensocial-tutorial-trial.googlecode.com/svn-history/r180/trunk/os-as-lib-081-test/src/AppDataExampleOrkut.mxml

February 18, 2009

requestSendMessage Example with Callback


    private function sendEmail():void
{
var msgParams:Object = {};
msgParams
[com.nextgenapp.opensocial.Message.Field.TITLE] = 'test title';
msgParams
[com.nextgenapp.opensocial.Message.Field.TYPE] = com.nextgenapp.opensocial.Message.Type.EMAIL;

var message:Message = container.newMessage("test msg body", msgParams);
container
.requestSendMessage(["VIEWER"], message, sendEmailCallback);
}
private function sendEmailCallback(respItem:ResponseItem):void
{
// note: requestSendMessage() returns ResponseItem, not DataResponse.
trace
("sendEmailCallback");
Alert.show("sendEmailCallback. haderror=" + respItem.hadError());
if (respItem.hadError()) {
// get the response item
Alert.show("sendEmailCallback. errorCode=" + respItem.getErrorCode() + ". errorMessage=" + respItem.getErrorMessage());
}
}

A full sample code can be found here: http://opensocial-tutorial-trial.googlecode.com/svn-history/r180/trunk/os-as-lib-081-test/src/SendMsgExampleOrkut.mxml

requestSendMessage() callback returns a ResponseItem, not DataResponse.

The following is javascript api behavior:
This is common knowledge if you have use requestSendMessage() before. requestSendMessage()’s callback function gives you a ResponseItem, not DataResponse. In other functions like fetchPeopleRequest, it will return a DataResponse.

Since the javascript api behaves this way, our actionscript library will behave the same way.

Eg.
private function sendEmail():void
{
var msgParams:Object = {};
msgParams[com.nextgenapp.opensocial.Message.Field.TITLE] = 'test title';
msgParams[com.nextgenapp.opensocial.Message.Field.TYPE] = com.nextgenapp.opensocial.Message.Type.EMAIL;

var message:Message = container.newMessage("test msg body", msgParams);
container.requestSendMessage(["VIEWER"], message, sendEmailCallback);
}

private function sendEmailCallback(respItem:ResponseItem):void
{
// note: requestSendMessage() returns ResponseItem, not DataResponse.
trace("sendEmailCallback");
Alert.show("sendEmailCallback. haderror=" + respItem.hadError());
if (respItem.hadError()) {
// get the response item
Alert.show("sendEmailCallback. errorCode=" + respItem.getErrorCode() + ". errorMessage=" + respItem.getErrorMessage());
}
}

Changing constant value to small case

Currently, field constants have upper-case value.
eg.

public static const THUMBNAIL_URL:String = "THUMBNAIL_URL";




However, according to the spec, the value has been standardize to lower-case.

An excerpt of the spec on http://wiki.opensocial.org/index.php?title=Opensocial.Person_(v0.8)

opensocial.Person.Field.THUMBNAIL_URL

Person's photo thumbnail URL, specified as a string. This URL must be fully qualified. Relative URLs will not work in gadgets. This field may be used interchangeably with the string 'thumbnailUrl'.



So we will start changing the value to lower case soon.


eg.

public static const THUMBNAIL_URL:String = "thumbnailUrl";