Developer guide

Getting familiar with applications in the itimes environment

Each OpenSocial container has a different development experience. This section will familiarize you with the process of developing applications specifically for itimes.

itimes application terminology
Activity stream A collection of activities created by OpenSocial applications on behalf of itimes users. These activities are mixed with other notifications in the "friends update" box on the itimes home page.
Application Third party code that uses the gadgets and OpenSocial APIs to extend the itimes experience.
Add Application page Add application page listing all available applications.
Application preview page A page unique to each application where users can see the description and preview of the app and prevent it from posting to their activity stream. For users who do not have the app installed, the page doubles up as the application install page.
Manage Application page Manage Application page lists all applications installed by a user and allows the user to add, remove and submit for approval.
Application specification An XML file that defines the application. Syntax is based on gadget XML.
Canvas View The full page view of an application.
Profile View The View of an application on a user's profile
Preview View The view of an application on the Application Preview page.
View The location where an application is displayed. In itimes, applications can be displayed on either of the Canvas, Profile or Preview views.
Anatomy of an itimes application
Before building applications for itimes, it is useful for a user to first familiarize himself with the itimes application platform. A helpful guide is the 'Anatomy of an itimes Application' which serves as a visual guide for all enhancements that have been added to enable itimes to host applications
Installing your application in itimes
Applications need to run inside a container in order to access social network data. itimes offers a Developer Sandbox where you can access the OpenSocial APIs and other new features. If you do not have access to http://sandbox.itimes.com (i.e. if you get redirected to http://www.itimes.com when you try to access the Sandbox), you have to create a Sandbox account.
Inside the Sandbox, navigate to Manage Application by clicking the 'My Sandbox' link.

The 'Manage Applications' list will be empty if you are using the Sandbox for the first time, but you should see a block 'Add application by URL'.
Paste the URL of your application specification into this field and press the 'Submit' button. You will be taken to the Application Preview page which displays the app's name, description and preview, if any, along with the privileges that you grant the application by installing it. This page also shows ratings and comments from other users once your app is live in the directory.

Some privileges must be granted for the application to function, but you can also choose whether to allow the application to post to your activity stream. Check the boxes next to the optional permissions you wish to grant to the application."

This application is automatically installed onto your page."

Click on 'Go to application'. You are automatically redirected to the Canvas page. Now if you return to the Manage Application page, you will see the newly installed application listed on the page."

Now, go to the profile page to see the application running in its Profile view.
OpenSocial applications

Now that you have learned the basics of installing and updating applications, here are some tips and tricks that will help you build robust social applications for itimes:

OpenSocial applications are a new type of application, based on the gadgets technology, but extended to interact with social data retrieved from a website from a website (also referred to as a container) that supports the OpenSocial API. itimes is an example of an OpenSocial container and this section focuses on the development aspects of working with OpenSocial applications specifically within the itimes environment.

itimes querystring parameters

itimes provides several query string parameters that give one additional data about the context in which one's application is running. These parameters can be parsed manually using window.location.href Alternatively, one can use the gadget convenience function gadgets.util.getUrlParameters. Below is a list of available parameters with their corresponding example values:

Name How to retrieve Example value
Country gadgets.util.getUrlParameters()["country"] US
Language gadgets.util.getUrlParameters()["lang"] en-US
Owner ID gadgets.util.getUrlParameters()["owner"] 12345678901234567890
Viewer ID [1] gadgets.util.getUrlParameters()["viewer"] 12345678901234567890
Parent URL gadgets.util.getUrlParameters()["parent"] http://sandbox.itimes.com
Gadget URL gadgets.util.getUrlParameters()["url"] http://example.com/gadget_specification.xml
View Name gadgets.util.getUrlParameters()["view"] canvas
View Parameters gadgets.util.getUrlParameters()["view-params"] {"foo":12345,"bar":"Bar value"}

[1] Only available if the viewer has the gadget installed.

Determining the current Application View
In itimes, one's application may be displayed in the Canvas and Profile views. Because the Profile view is much smaller, it is recommended that one designs separate user interfaces for each. This is done by including multiple content elements in one's application spec. Since a user now has more than one view, there may be occasions when he / she needs to programatically determine which view is currently being displayed. The easiest way to establish the Current view is by using the View URL parameter mentioned above which returns either 'Profile' or 'Canvas'. In order to get a reference to a View object, one can use the 'Views' feature in their app specification's ModulePrefs element.
<ModulePrefs title="Views example">
  <Require feature="views" />
</ModulePrefs>

When the Views feature is included, one can obtain the current view by calling the gadget.util.getCurrentView() method which returns a gadgets.views.View object. See Available views in itimes for a listing of views that may be returned by this call.

The following example demonstrates how to get the Current view and conditionally execute a code against the returned value:

function getViewName() {
  return gadgets.views.getCurrentView().getName();
};
if (getViewName() == "canvas") {
  /* Do canvas specific stuff here */
}
if (getViewName() == "profile") {
  /* Do profile specific stuff here */ }
Available views in itimes
To use the code in this section, the user must include <Require feature="views"/> in the ModulePrefs section of his/her application.

One can obtain the available View objects by calling gadgets.views.getSupportedViews:

var supported_views = gadgets.views.getSupportedViews();

The object returned by the getSupportedViews call contains gadgets.views.View objects representing all of the available views in itimes, indexed by View name. Currently, these are:

View Code to retrieve
Profile supported_views["profile"]
Canvas supported_views["canvas"]
Each view corresponds to a different itimes page:
Profile and DASHBOARD correspond to a user's profile view. Profile URLs look like:
http://www.itimes.com/users/username
Canvas and FULL_PAGE correspond to the maximized view of an application. Canvas URLs look like:
http://sandbox.itimes/os_application.php? uid=xxx&app_id=xxx&mod_id=xxx
Default does not correspond with any itimes view. This view is returned for compatibility with the multiple content section feature of the gadget specification. You should not use this view for navigation.

In addition to requesting a view by name, you can also obtain a view by using a ViewType object. This allows you to obtain a type of view with specific properties without referring to the view by name.

The following table shows you how ViewType objects may be used and which views they map to on itimes:

Name Code to retrieve Canvus
profile supported_views["profile"] Profile
canvas supported_views["canvas"] Profile
My Updates

My Updates serve as an alert for activities done around the user and can be leveraged by applications in a similar way as Home page updates can be. img
Navigating to another view

To use the code in this section, make sure you include <Require feature="views"> in the ModulePrefs section of your application.

If you want to provide links between views (ie. link from the Profile view to the Canvas page), gadgets.views.requestNavigateTo is the method to use. All you need to do is pass in a View object returned from getSupportedViews which is described in Available Views in itimes above. The following code sample demonstrates this method:

function navigateTo(dest) {
  var supported_views = gadgets.views.getSupportedViews();
  gadgets.views.requestNavigateTo(supported_views[dest]);
};
/**
 * When called, this method asks the container to switch to the canvas
 */
function gotoCanvas() {
  navigateTo("canvas");
};
/**
 * When called, this method asks the container to switch to the profile
 */
function gotoProfile() {
  navigateTo("profile"); };

An alternative is to create a new View object manually and use it to initiate navigation. The following code sample shows how to create a new gadgets.views.View object and pass it to the gadgets.views.requestNavigateTo() method:

An alternative is to create a new View object manually and use it to initiate navigation. The following code sample shows how to create a new gadgets.views.View object and pass it to the gadgets.views.requestNavigateTo() method:

 * When called, this method asks the container to switch to the canvas
 */
function gotoCanvas() {
  var canvas_view = new gadgets.views.View("canvas");
  gadgets.views.requestNavigateTo(canvas_view);
};
/**
 * When called, this method asks the container to switch to the profile
 */
function gotoProfile() {
  var profile_view = new gadgets.views.View("profile");
  gadgets.views.requestNavigateTo(profile_view); };};
l
Obtaining the application's ID
You can obtain the application's ID number in itimes with the following call: var application_id = gadgets.util.getUrlParameters()["aid"]; After executing the snippet above, application_id will contain the same value as the appId parameter in your application's itimes URL.
Passing data to your application through requestNavigateTo()

To use the code in this section, make sure you include <Require feature="views"> in the ModulePrefs section of your application.

If you are using gadgets.views.requestNavigateTo, you may supply an optional parameter containing data to be passed to the new page.

The following code passes two variables: foo and bar to the canvas view of the current application:

function gotoCanvas(params) {
  var canvas_view = new gadgets.views.View("canvas");
  gadgets.views.requestNavigateTo(canvas_view, params);
};
var my_params = {
  "foo": 12345,
  "bar": "Bar value"
};
gotoCanvas(my_params);
function navigateTo(dest) {
  var supported_views = gadgets.views.getSupportedViews();
  gadgets.views.requestNavigateTo(supported_views[dest]);
};
/**
 * When called, this method asks the container to switch to the canvas
 */
function gotoCanvas() {
  navigateTo("canvas");
};
/**
 * When called, this method asks the container to switch to the profile
 */
function gotoProfile() {
  navigateTo("profile"); };

An alternative is to create a new View object manually and use it to initiate navigation. The following code sample shows how to create a new gadgets.views.View object and pass it to the gadgets.views.requestNavigateTo() method:

An alternative is to create a new View object manually and use it to initiate navigation. The following code sample shows how to create a new gadgets.views.View object and pass it to the gadgets.views.requestNavigateTo() method:

 * When called, this method asks the container to switch to the canvas
 */
function gotoCanvas() {
  var canvas_view = new gadgets.views.View("canvas");
  gadgets.views.requestNavigateTo(canvas_view);
};
/**
 * When called, this method asks the container to switch to the profile
 */
function gotoProfile() {
  var profile_view = new gadgets.views.View("profile");
  gadgets.views.requestNavigateTo(profile_view); };};
l
Obtaining the application's ID
You can obtain the application's ID number in itimes with the following call: var application_id = gadgets.util.getUrlParameters()["aid"]; After executing the snippet above, application_id will contain the same value as the appId parameter in your application's itimes URL.
Passing data to your application through requestNavigateTo()

To use the code in this section, make sure you include <Require feature="views"> in the ModulePrefs section of your application.

If you are using gadgets.views.requestNavigateTo, you may supply an optional parameter containing data to be passed to the new page.

The following code passes two variables: foo and bar to the canvas view of the current application:

function gotoCanvas(params) {
  var canvas_view = new gadgets.views.View("canvas");
  gadgets.views.requestNavigateTo(canvas_view, params);
};
var my_params = {
  "foo": 12345,
  "bar": "Bar value"
};
gotoCanvas(my_params);
You should see that after the navigation has taken place, your URL will look like:
http://sandbox.itimes.com/os_application.php? app_id=#####&uid=#####& appParams=%7B%22foo%22%3A12345%2C%22bar%22%3A%22Bar%20value%22%7D

In the Canvas view, check for these values with the following code:

var prefs = gadgets.views.getParams();
var foo = prefs["foo"]; // foo contains 12345
var bar = prefs["bar"]; // bar contains "Bar value"

Caution: In itimes, the Profile view may contain more than one application, which makes targeting data to a specific application impossible. Therefore, you can only pass data in this manner to the Canvas view of an application. Data passed to the Profile view

Passing data to your application through the query string

To use the code in this section, make sure you include <Require feature="views"/> in the ModulePrefs section of your application.
There may be cases where you need to pass data to your application's Canvas view from the query string. itimes allows for a special URL parameter named "appParams" that a user can use to pass data to his / her application. For example, going to the URL

http://sandbox.itimes.com/os_application.php?app_id=#####& appParams=%7B%20%22hello%22%20%3A%20%22hi%22%20%7D

(where ##### is your application's ID number) will forward a parameter named hello with a value of hi to your application. You can retrieve this parameter in the following manner:

var querydata = gadgets.views.getParams();
var hello = querydata["hello"]; // hello contains the value "hi"

%7B%20%22hello%22%20%3A%20%22hi%22%20%7D represents a URL-encoded version of a JSON encoded object, which is the format itimes expects the appParams value to be in. If you wish to pass data to your applications, you will need to define a JavaScript object and assign an encoded, serialized version of this object to the appParams URL argument.

For example, to pass variables foo with value 12345 and bar with value "Bar value", first place these values in an object:

var data = { "foo": 12345,
             "bar": "Bar value" };

To serialize this object into a JSON string, you can use the gadgets.json.stringify function, or any other JSON library.

var json_data = gadgets.json.stringify(data);

json_data will contain the value {"foo":12345,"bar":"Bar value"} after running the previous two code snippets. To escape this value for use in a query string, use the encodeURIComponent JavaScript function:

var url_data = encodeURIComponent(json_data);

url_data will contain the value
%7B%22foo%22%3A12345%2C%22bar%22%3A%22Bar%20value%22%7D after executing the previous snippets. You may now use this value in the appParams query string parameter to pass your data to your application:

http://sandbox.itimes.com/os_application. php?app_id=#####&appParams=%7B%22foo%22%3A12345%2C%22 bar%22%3A%22Bar%20value%22%7D

This approach is more difficult to use than the requestNavigateTo approach outlined in Passing data to your application through requestNavigateTo(), but the links one generates in this manner can be displayed on external websites or in activity stream entries.

Linking to pages inside your application

To use the code in this section, make sure you include <Require feature="views"/> in the ModulePrefs section of your application
A user may combine some of these techniques to create URLs that can link to different pages in his / her application. If a user wishes to provide a link to an 'About' page in their application, he / she needs to dynamically generate a link like

http://sandbox.itimes.com/os_application.php? app_id=XXXXXXXX&uid=YYYYYYYY&appParams=%7B%22page%22%3A%22about%22%7D

where XXXXXXXX is the application's ID and YYYYYYYY is the itimes UID of the person one wishes to link to . URLs in this format can be constructed in the following manner:

function makeLink(page, app_id, uid) {
  return [ gadgets.util.getUrlParameters()["parent"],
       "/os_application.php?app_id=",
      app_id,
   "   &uid=",
     uid,
     "&appParams=%7B%22page%22%3A%22",
     page,
     "%22%7D" ].join("");
};
var about_url = makeLink("about", stored_app_id, stored_uid);

You can print these links in a user's activity stream or even on an external website.

If you want to redirect a user to the 'About' page without necessarily generating a URL, call gadgets.views.requestNavigateTo with extra parameter data:

function gotoPage(to_page) {   var canvas_view = new gadgets.views.View("canvas");
  var params = {};
  params["page"] = to_page;
 gadgets.views.requestNavigateTo(canvas_view, params);
};
gotoPage("about");

In your application, switch on the value of the page parameter to choose which page to render:

var page = gadgets.views.getParams()["page"];
 
if (page == "about") {
  renderAboutPage();
} else {
  renderNormalPage();
}

This code will work regardless of the method a user chooses to pass the page parameter to their application.


Activity streams
Activity streams allow developers to send notifications to a user's friends about activities that the user has done while interacting with an itimes application. Activity streams are rendered as 'Updates' in the itimes user interface. Updates are also shown on the home page.
Updated itimes Activity Stream policies
Applications are extensions of a user's profile. itimes' Activity Stream policies are the same as other parts of the site. Activities are generated by calling:
opensocial.requestCreateActivity. Notice that one needs to request that an activity be posted A container may choose not to post the activity in certain situations. The following list shows when calls to requestCreateActivity will and will not succeed in itimes:
  • Activities can be posted when owners are interacting with an application running on their own profile. The resulting activity stream entry will be posted to the owner's activity stream.
  • Activities will not be posted when a user interacts with applications on their friends' profiles or when friends interact with applications on the owner's profile.
Profile data
The OpenSocial API provides access to a users' profile data. Not all of this data is available by default, so this section explains what information is available to applications on itimes.
itimes' profile data policies

For an application to access user profile data, the user must have granted access to the app by choosing to install it on his / her own profile.

The data that will be made available to applications will only be data that users have marked as being visible to everyone. Data that is restricted to friends or friends of friends will not be available to applications.

List of profile fields

This section lists all the profile fields available through OpenSocial, and itimes' access policy for each. The following policy labels are used:



Available Data will be made available to the application if the user has the application installed AND has chosen the "Share with Everyone" privacy setting for the field in question.
Not Applicable (N/A) These fields are not included in itimes and hence are not available to applications.
Not Yet Implemented These fields may be available to apps in the future.
Personally Identifiable Informatio These fields are not available to applications.
Profile fields

itimes field OpenSocial field itimes access policy
First name NAME (GIVEN_NAME) Available
Last name NAME (FAMILY_NAME) Available
Profile URL PROFILE_URL Available
Thumbnail URL THUMBNAIL_URL Available
Gender GENDER Available
Relationship status RELATIONSHIP_STATUS Available
City, State, Country CURRENT_LOCATION, ADDRESSES Available
Languages I know LANGUAGES_SPOKEN Available
High school SCHOOLS Available
College / university SCHOOLS Available
Interested in LOOKING_FOR Available
Pets PETS Available
Webpage URLS Available
About me ABOUT_ME Available
Books BOOKS Available
Music MUSIC Available
TV Shows TV_SHOWS Available
Movies MOVIES Available
Cuisines FOOD Available
Primary email EMAILS Available
Secondary emails EMAILS Available
Land line PHONE_NUMBERS Available
Cell phone PHONE_NUMBERS Available
Address CURRENT_LOCATION, ADDRESSES Available
City, State, Country CURRENT_LOCATION, ADDRESSES Available
High school SCHOOLS Available
College / university SCHOOLS Available
Major N/A N/A
Degree N/A N/A
Year SCHOOLS (END_DATE) Available
Status STATUS Available
Turn ons TURN_ONS Available
Turn offs TURN_OFFS Available