The latest iteration of OpenSocial on MySpace, OpenSocial 0.8, sets a number of places where you now need to understand this JavaScript class known as opensocial.IdSpec. Before, when you needed something like the viewer or owner from an OpenSocial 0.7 method, you would just pass a string indicating 'VIEWER' or 'OWNER' and all would be fine. However, to make the ids more informative and to allow for passing IDs that belong to people or groups, the IdSpec was created. Many methods in OpenSocial take an IdSpec as a parameter. Let’s take a simple example (simple because I happen to have the 0.7 and 0.8 version handy!). In 0.7, if I wanted to get a list of the viewer’s friends and display that list to an HTML select control, I would have the following BLOCKED SCRIPT
function loadFriends(selectId) {
var friendSelect = document.getElementById(selectId);
var dr = opensocial.newDataRequest();
var pplReq = dr.newFetchPeopleRequest('VIEWER_FRIENDS');
dr.add(pplReq, 'fetchPeople');
dr.send(function(response) {
var ppl = response.get('fetchPeople').getData().asArray();
var i;
var html = "";
for (i = 0; i < ppl.length; ++i) {
var person = ppl[ i ];
html += "<option id='" + person.getField(opensocial.Person.Field.ID) + "' value='" +
person.getDisplayName() + "'>" + person.getDisplayName() + ": " +
person.getField(opensocial.Person.Field.ID) + "</option>";
}
friendSelect.innerHTML = html;
});
}
In that code, note that to access the list of friends, I just pass in the string 'VIEWER_FRIENDS' and everything works. For 0.8, the code needs a modest change. It needs an IdSpec. The code to create the DataRequest and FetchPeopleRequest becomes either
var dr = opensocial.newDataRequest();
var params = {};
params[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;
params[opensocial.IdSpec.Field.GROUP_ID] = opensocial.IdSpec.GroupId.FRIENDS;
var idspec = opensocial.newIdSpec(params);
var pplReq = dr.newFetchPeopleRequest(idspec);
or, to get the friends whose network distance is 1 from the viewer (just the immediate friends), you can use:
var dr = opensocial.newDataRequest();
var params = {};
params[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.VIEWER;
params[opensocial.IdSpec.Field.NETWORK_DISTANCE] = 1;
var idspec = opensocial.newIdSpec(params);
var pplReq = dr.newFetchPeopleRequest(idspec);
This is a bit more wordy, but it allows for a uniform API across the methods that accept an IdSpec. For a full explanation of the mapping from the 0.7 to the 0.8 API, please see the OpenSocial v0.8 Breaking Changes Document.