Constant Contact Labs Developer Blog

  • A Week With OpenSocial Posted Wednesday, February 17, 2010 Brendan White 3 Comments

    If you have visited the Labs website before or know anything about the group then you are aware of our commitment to researching new technologies.  Cool Stuff Week was in part about devoting a week to look into these new technologies without necessarily being sold on their potential benefit.  I spent my week working mostly on OpenSocial, a set of common APIs for developing social networking applications and social mashups.  If you are interested in OpenSocial or developing social applications for your small business or otherwise read on.

    A Little About OpenSocial

    OpenSocial was developed by Google, MySpace, and a number of other social networks.  It is based on HTML, JavaScript and the Google Gadgets framework.  It seems clear from the documentation and API references that OpenSocial was intended to be a functional equivalent of FaceBook, only "open".  Instead of FaceBooks's Users and Friends APIs you have OpenSocial's People and Friends, instead of a Feed API you have an Activity API, and instead of a Data Store API you have the Persistence API.  The OpenSocial APIs use JavaScript and XML instead of proprietary languages like FaceBook's FBJS and FBML.  So what makes OpenSocial different?  The big benefit of using OpenSocial over FaceBook is that with OpenSocial you can create one social application that can run on any social networking site that supports the OpenSocial APIs.

    Quick API Overview

    OpenSocial uses three main APIs mentioned earlier, People and Friends, Activities, and Persistence Data.  The People and Friends APIs are used to retrieve information about a user or the user's friends in JSON, Atom Pub XML, or a custom OpenSocial XML response. This response can include information about a person such as Address, BodyType, Name, Phone, etc…  The Activities APIs allow OpenSocial applications to update and access the activity stream of networking websites.  These steams can be news feeds, messages to or from friends, invitations to or from friends, or any kind of updating mechanism used on a supporting site.  Finally, the Persistence API allows the storage and retrieval of key-value pairs that are both user specific and app specific or global to the application. 

    The Idea

    To determine whether or not OpenSocial was a technology worth further investigation the idea was to:

    • Gain some knowledge of the OpenSocial APIs
    • Develop a small application to demonstrate the APIs integrating with Constant Contact data
    • Install the sample application on a few social networking sites to test interoperability
    • Determine if OpenSocial is a technology we might leverage in the future

    What I used

    One thing I found rewarding about Cool Stuff Week was working with new supporting technologies I didn't initially plan on using such as Google App Engine and Django.

    • Orkut to test my application
    • Google App Engine to host the web application
    • Django Python to form the HTML responses to requests for CTCT data
    • Google Sites to host the XML Google Gadget file
    • Google Gadget Editor is a WYSIWYG editor for creating Google Gadgets (Can also be downloaded as a Gadget)
    • CodeRunner is an app that runs on orkut.com that is useful for testing API functionality without creating an application and installing it. (In Orkut.com, search for "CodeRunner" under app search.)

    The Results

    CodeRunner (mentioned above) came in handy for testing and learning the OpenSocial API functionality.  For example to fetch the owner of an application, that is the person whose profile hosts it, you would use the following code:

    //create a new data request
    var request = opensocial.newDataRequest();
    //add a person request and specify the owner ('owner' is key for retrieval)
    request.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER), 'owner');
    //fetch the owner
    request.send(getOwnerCallback)
    
    function getOwnerCallback(response) {
      //get the owner response by key
      var ownerResponse = response.get('owner');
     
      //if there was not an error continue
      if (!ownerResponse.hadError()) { 
        //if successful, get owner data and show the display name
        var owner = ownerResponse.getData(); 
        alert(owner.getDisplayName());
      }
    };
    

    Creating an activity such as an update on a profile is simple using OpenSocial.  See the following code:

    friends = getFriends();
    friendId = '1234';
    //activity title
    var title = friends.getById(friendId).getDisplayName() + ' did X.';
    
    //create and store the parameters for the activity request
    var params = {};
    params[opensocial.Activity.Field.TITLE] = title;
    var activity = opensocial.newActivity(params)
    
    //make the activity request
    opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH, function() {}); //ignore callback
    

    To write persistent data for example to save a viewer’s (the individual using the hosted app) IP address you could use the following code:

    //get the ip address of the current viewer
    ipAddress = getIpAddress()
    var request = opensocial.newDataRequest();
    reqest.add(req.newUpdatePersonAppDataRequest("VIEWER", "ip_address", ipAddress),
        "set_data");
    reqest.send(putDataCallback);
    
    function putDataCallback(response) {
      if (response.get("set_data").hadError()) {
        /* The update failed ... do something */
      } else {
        /* The update was successful ... do something else*/
      }
    };
    

    Demo App Summary

    For my demo application I created an OpenSocial App that allowed an owner to add contacts to his/her Constant Contact Mailing List (similar to the Labs FaceBook Application).  Along with the email address of a contact, social data such as their display name, social site, and other arbitrary information was uploaded as custom fields to Constant Contacts APIs.

    What Social Sites are Supported?

    LinkedIn, MySpace, Friendster, Hi5, and many more.

    Developing for Multiple Social Sites, "Write Once, Run Anywhere" isn't exactly true.

    It's not accurate to say that every application developed for OpenSocial will run on all supported social websites (called Containers). There are some things to consider when developing an OpenSocial application for multiple social networks.

    Approval

    Many of the sites that support the OpenSocial APIs have some sort of approval process that an application must pass before it is allowed on the application directory.  Friendster will allow you to post anything for example but Hi5 must approve your application first.  Most disappointing to me in this regard was that LinkedIn (a supporting site of OpenSocial) makes it extremely difficult to post an application.  You must first submit a proposal and judging by how many applications they have listed in their directory (thirteen at current) your idea is likely to be turned down or ignored.

    API Versions and Implementation

    Not every container uses the same API version and also does not necessarily implement the features in the same way.  For example if an application relies on a viewers photos being accessible then there are some sites that will either not support this or not allow it.  Here is a useful compliance link for determining functionality across a range of sites or containers:

    Policies

    A feature that is fine on one container might not be acceptable on another.  All containers have their own policies with regard to applications and ensuring that your application doesn't break any of these on your target containers is crucial.  For example if your application relies on iFrames and your application gets rejected because a container doesn't allow them then you are out of luck.

    In the end

    I enjoyed working with OpenSocial during Cool Stuff Week.  OpenSocial provides developers familiar with HTML, XML, and JavaScript an easy way to create social applications that can be installed on a large group of social networking sites.  The technology is there, so the question seems to be: Am I interested in developing an application for any of the supported sites?  Given the difficulty developing for LinkedIn I would say probably not for most small businesses.  I’d be happy to hear from anyone who has used or plans to use OpenSocial, so post a comment below.

     
    The opinions expressed here represent those of the author and not those of Constant Contact, Inc. Read Blog Terms
    Next Post Previous Post
     

Comments (3) +comment on this post
 

  • Art | 9:33 PM April 27, 2010

    I wouls like to know if you compared this Open Social to any others out there. I would like this compared to Social Network

  • Mark W. | 1:38 PM April 28, 2010

    I’d like to know what you’d want to make OpenSocial better/easier/et…. Since this is an open community, being able to post an objective look at where we are would be helpful.

    Thanks!

  • Reneldy Senat | 2:20 PM April 28, 2010

    @Art we haven’t compared Open Social to other API’s, yet. But, did you have a specific one in mind?

    @Mark we will work on getting some additional information up for you.

Add your comment below

Remember me

Please enter the word you see in the image below:


*  Please be aware that all comments are moderated.

Recent comments

05/16/12 Alex wrote:

Hi Constant Contact,

How can we change the text fields on the second screen of the Join My List app? I’d like to add fields that are important to us and eliminate some of the others we don’t care about and therefore would prefer our subscribers not be asked.

Interested in a particular topic?

If there are specific topics you’d like to see us discuss on our blog or other ideas you’d like to share, please let us know. Click here to contact us.