Showing posts with label opensocial. Show all posts
Showing posts with label opensocial. Show all posts

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

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";

requestSendMessage() is implemented

We have implemented opensocial.requestSendMessage().

Here is the excerpt example code:

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



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

Difference between email & notification on Orkut

I am wondering: is there a difference between email & notification on Okrut? I tried requestSendMessage() with email and notification. They seem to do exactly the same thing. Both result in an email being sent. Is there a differnce?

February 17, 2009

DataResponse.getErrorMessage() showing undefined for updatePersonAppData

I was testing updatePersonAppData on orkut. I deliberately tried to create an error by giving a wrong id such as "" instead of "VIEWER". I find that hadError() does return true, but getErrorMessage() returns undefined. I kind of expected getErrorMessage() to return something interesting to help us debug. Sadly, it returns undefined.

February 16, 2009

Preliminary AppData implementation

Preliminary AppData implementation is completed and tested. You can update and fetch AppData. Escape character is not yet supported.

To update app data


var dr:DataRequest = container.newDataRequest();
dr.add(dr.newUpdatePersonAppDataRequest("VIEWER", "testdatakey1", "testdata1"));
dr.send(updatePersonAppDataCallback);


To fetch app data


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));
dr.send(updatePersonAppDataCallback);


The usage of the api is exactly the same as the opensocial javascript api.

If you have any questions about usage of these 2 functions or you feel the interface method is that the best, please send your suggestions to us.

fetchPersonAppData data structure

opensocial javascript API's fetchPersonAppData returns an object with the following structure:
- person_id
   - [key, value]
   - [key, value]
- person_id
   - [key, value]
   - [key, value]

This structure retain the maximum flexibility so that it can return multiple person and multiple key at the same time. However, it can easily confuse first-time users of our library if we return the raw data. We are thinking whether we should return a more structured data back to the caller.

Structure:


AppData
   - PersonData
     - DataElement
     - DataElement
   - PersonData
     - DataElement
     - DataElement


AppData.getPersonDatas() returns an Array of PersonData object. Each PersonData contains an array of DataElement. Each DataElement is a [key, value] pair.


Advantage of returning a structured data
It will be easier for the user of our library to decipher the data. Flex Builder's code-helper will be useful in this case. Without refering back at the javascript documentation, user can still figure out the data structure of the data being returned.

Disadvantage
It will be a departure from the javascript API.


If you have strong feeling about going one way or the other, please let us know.

February 14, 2009

opensocial javascript api rants

Opensocial javascript api is very flexible, this is a benefit when there are multiple containers need to implement the same standard. It also allows batch multiple commands. I think people already know its advantages, so I’m not going to rant about advantages. I’m just going to do some ranting about some of the shortcomings that comes with these flexibilities.

1. cumbersome

Instead of one call like:
opensocial.person.getViewer();
it takes 4 lines to do the same thing. The following code is not actual code, it only illustrates the point.
var req = opensocial.newDataRequest();
var personReq = req.newFetchPersonRequest();
req.add(personReq, “…”);
req.send();


2. usually, when there is objects, it is easy to infer the data structure. With getField()/setField() instead of property, it is harder to infer data structure. Also, we don’t get the benefit of the code-helper by IDE.


Solution?

To address #1:
Perhaps we should have some new api call build on top of the existing api to make things more terse:

Eg.
OpensocialShortcut.person.getViewer();
OpensocialShortcut.person.getFriends();
OpensocialShortcut.data.update();
OpensocialShortcut.data.fetch();



To address #2:
On the actionscript api, perhaps we should have extension to allow people to access object properties like this:
person.name.firstName
person.gender.getKey()


instead of
person.getField(opensocial.Person.Field.NAME).getField(opensocial.Name.Field.FIRST_NAME);
person.getField(opensocial.Person.Field.GENDER).getKey();


---------

What do you think? Is it better to have the API call featured like the one shown in “Solution” section?

February 11, 2009

Overview

Opensocial-actionscript-client blog

This blog will show the development activities and some general rants and discussion about opensocial-actionscript-client project. opensocial-actionscript-client is an opensource library for actionscript (and Flex/Flash) to use opensocial API. :)

The code is opensourced and hosted at:
http://code.google.com/p/opensocial-actionscript-client

The download is located at:
http://code.google.com/p/opensocial-actionscript-client/downloads/list

New update are shown at:
http://code.google.com/p/opensocial-actionscript-client/updates/list

What is opensocial-actionscript-client api
Opensocial-actionscript-client is an OpenSocial library for Actionscript/Flex/Flash. This is an opensource library. It allows Actionscript/Flex/Flash client to access OpenSocial API.

A Little More Detail About the Architecture
The library uses Opensocial Javascript API, not REST API. It was a careful and necessary decision to go for Javascript API for the following reasons:
1. Some containers have a closed-off crossdomain.xml (which means Flash cannot connect to their server)
2. Not all containers support REST API yet
These are restrictions that cannot be overcome, unless the containers (the social networks sites) change their policies.

Current OpenSocial Version
Currently, the API uses OpenSocial 0.8, the latest version at the moment.

Contribution/Feedback
You are welcome to contribute or add to the library. It is opensource! :)