This article will guide you through the OpenSocial APIs and show you how to build a couple of social applications to share interests with friends. Figure 1 and Figure 2 show the final results: two applications, loaded within the orkut container to share travel experiences and movie preferences with a network of friends.
|What You Need
|The OpenSocial APIs
|A Java Development Kit (JDK)
|Java Apache Tomcat
A social network is an ensemble of users who are linked to each other through a series of relationships (being friendly, being work colleagues, sharing common interests). Each user is characterized by a state or profile, which is a collection of all the variables required to describe the user fully, such as name, gender, hobbies, work, or contact information. Each user also has a series of relationships that link him to his own friends on the network. Some networks also support the concept of activities: streams of actions performed by the user within the network that alter his state or the set of his relationships with other people.
The OpenSocial APIs provide access to all these entities and are divided into the following major components, each responsible for a specific task:
- People and relationships: for accessing information on the user who is interacting with the application, his profile, and his relationships on the network
- Persistence: for manipulating the user state or profile and saving and loading additional information related to the user and required by the application
- Activities: for interacting with the user’s activities stream, publishing new activities performed by the user, or listening to events that occurred to the user’s friends
|Author’s Note: The content is exclusively the personal opinion of the author. Under no circumstances should the content be attributed to any employer, past, present, or future, of the author, unless so stated explicitly by that individual or organization.
Shindig: A Local Development Environment
OpenSocial applications live within an OpenSocial Container that maintains the application state and information about the users and the social network they compose. Other popular containers include orkut, hi5, or MySpace. For OpenSocial application development, you can either run your code within sandboxed environments, which many containers provide, or use a container running on your local machine specifically for development purposes. (The OpenSocial “Getting Started” tutorial lists available containers on the web and the development features they support, in case you prefer that option.) The local environment option is preferable because it gives you unconstrained possibilities to test different scenarios, such as manipulating the list of friends, altering your activities stream, or impersonating different users.
In this article, you will set up a local development environment using Apache Shindig as your container. Shindig is an open source container that provides the reference implementation for the OpenSocial APIs. Therefore, you are assured that whatever application you create on your local environment will work on existing containers on the web. Once the application is finished, you may then deploy it on the web and include it in public directories (such as the orkut application gallery), so that users can include it within their personal pages and profiles and start spreading the word!
Start by downloading the Shinding container from the project website. Since no packaged version yet exists, you have to download the source code and build it from scratch. The following instructions guide you through the process, assuming that you have a Java Development Kit (JDK), Subversion, and Maven2 installed on your system (as described on the Shindig website):
mkdir ~/shindigcd ~/shindigsvn co http://svn.apache.org/repos/asf/incubator/shindig/trunk/cd ~/shinding/javamvn package
Once the build finishes, you will have a WAR file suitable for deployment in a J2EE application server such as Apache Tomcat. Supposing that you have a working installation of Tomcat in your ~/tomcat folder (if you don’t, you can download it from the web and unpack it in your local disk by following this link), start up Tomcat using the following command:
Once started, access the Tomcat deployment manager at http://localhost:8080/manager/html and deploy the Shindig container. If you followed the instructions above, the WAR file will be located in ~/shindig/java/server/target/shindig.war. To work properly, the Shindig container must be deployed under the root context path, so be sure to un-deploy any application that may already be deployed under the same path before deploying Shindig. If everything goes accordingly, you should be able to access the URL http://localhost:8080/gadgets/files/samplecontainer/samplecontainer.html and see something similar to Figure 3.
Deploying Your Open Social Applications
You are now ready to deploy your applications. Every container uses its own process, but since your application is ultimately a Google Gadget, it:
- Goes to your container of choice and either adds the application by directly referencing the URL that points to the XML descriptor, or adds it to the gallery of available applications for that container.
For example, if you want to publish your applications on orkut (after enabling application development on your account as described in this article), just access sanbox.orkut.com and follow the “Edit Apps” link to add your application, specifying the URL for the XML descriptor file when requested. Then, it’s just about spreading the word to your network of friends and using your creations!
What Have We Learned?
In this article, you have learned what OpenSocial is and gone all the way from a basic example application in a local development environment to a full-featured application deployed in a live container. You can now further explore the OpenSocial APIs for features that were not discussed here, such as permission management and remote requests. Or you can start creating the next killer application and prepare to deploy it to your social network.