Capturing the User Profile

Due to the vast array of methods, social access functions, and container social hooks available, a developer has numerous options for accessing a user’s profile data. Two of the most popular consist of standardized AJAX request methods; both provide the same results, but they have radically different ways of getting there.

Old method

The traditional AJAX social request method—used as the primary request functionality up until OpenSocial 0.9—is newDataRequest. Even though it is more laborious, this method is widely used because it is backward compatible.

While method names and parameters for different data fetches change, you still have to call standard methods to set up a data request. When making a get request, we first set up our data request object using the newDataRequest method, as follows:

var req = opensocial.newDataRequest();

Now that the data request container object is available, we can create the key value parameter list to define the profile data that we capture. Our key indicates that we want to capture PROFILE_DETAILS, and the value array contains the list of OpenSocial Person fields that we want to capture. In this example, we are capturing the user’s name and thumbnail URL:

var params = {};
params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [
   opensocial.Person.Field.NAME,
   opensocial.Person.Field.THUMBNAIL_URL
];

We then add a newFetchPersonRequest call to our initial data request to indicate that we want to capture Person data ...

Get Programming Social Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.