Tuesday Aug 12, 2008

With the release of Version 0.8 of OpenSocial, there are some code changes needed if you try to update your gadgets from version 0.7 to 0.8. Specifically, the OpenSocial Release Notes mention the following changes:

  • VIEWER_FRIENDS and OWNER_FRIENDS have been removed.
  • opensocial.Activity.MediaItem is now opensocial.MediaItem.
  • opensocial.Person.Field.LOOKING_FOR now returns an opensocial.Enum.LookingFor object instead of a string.
  • opensocial.DataRequest.prototype.newFetchActivitiesRequest now returns a Collection.

Two other changes not noted in the Incompatible changes section of the Release Notes are the following:

  • opensocial.DataRequest.PersonId.OWNER is now opensocial.IdSpec.PersonId.OWNER.
  • opensocial.DataRequest.PersonId.VIEWER is now opensocial.IdSpec.PersonId.VIEWER.

Project SocialSite which is based on OpenSocial has migrated some gadgets from v0.7 to v0.8. The migrated gadgets have been updated to deal with the first incompatible change, namely the removal of VIEWER_FRIENDS and OWNER_FRIENDS, and the changes for OWNER and VIEWER. These changes are discussed next.

v0.8 Code Snippet

Below is a code snippet which shows how to make a request to retrieve the owner and the owner's friends data using the v0.8 API.

    var req = opensocial.newDataRequest();

    // owner
    req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER), 'owner');

    // friends
    var spec = new opensocial.IdSpec();
    spec.setField(opensocial.IdSpec.Field.USER_ID, opensocial.IdSpec.PersonId.OWNER);
    spec.setField(opensocial.IdSpec.Field.GROUP_ID, 'FRIENDS');
    spec.setField(opensocial.IdSpec.Field.NETWORK_DISTANCE, 1);

    req.add(req.newFetchPeopleRequest(spec), 'ownerFriends');

Explanation of v0.8 Code Snippet

Retrieving the owner data is similar to what was done for v0.7. The only change is the way the id (i.e. the first parameter in newFetchPersonRequest) is specified.

Retrieving the data for the owner's friends is now a little more involved. Previously the first argument to newFetchPeopleRequest could be a string (opensocial.DataRequest.Group.OWNER_FRIENDS if you were only retrieving the owner's friends). Now, the first argument is an IdSpec. Once you create the IdSpec object, then you need to set the various fields as defined here. Technically, I didn't need to set the GROUP_ID field since the default value is 1, and 1 means that the owner is friends with the people we're retrieving data for.

Going Forward

In a later blog I plan to cover the changes needed to retrieve activities using v0.8, so stay tuned.

In the meantime, if you're interested in checking out Project SocialSite you can download it from here. Also, if you have any questions or feedback on Project SocialSite, you can join the users@socialsite.dev.java.net mailing list from here once you're logged into the java.net site.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed