How to Create OpenSocial Application – Part 2

You can get viewer’s address information from Orkut thru opensocial APIs. Hi5 doesn’t support this feature yet although it would give you name and ID information. In Orkut Code Runner application, try the following code.

* CODERUNNER CODE TO GET Name, Opensocial ID, City and Profile URL
function response(data) {
var addresses =
var viewerLocality =

function request() {
var req = opensocial.newDataRequest();

var opt_params = {};
opt_params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.PROFILE_URL, opensocial.Person.Field.ADDRESSES];
(opensocial.DataRequest.PersonId.VIEWER, opt_params), "req");


You can download the above code from here.

Google code article had incorrect code to get the profile URL. Google opensocial group member yoichiro helped me to figure out the correct code. Yoichiro, if you happen to see this blog, many thanks to you again! Google code article is corrected now.

Get the name and address of viewer from orkut opensocial

In the above code, you create object for newDataRequest. Set the parameters to get the profile URL and addresses along with basic viewer information. If the newFetchPersonRequest succeeds, the code execute response(data).

If you query the resultant data for name and id, you would get it. This id is the opensocial id of the viewer. Orkut profile ID is different. It’s little tricky to get the city information of the viewer. The field name to get the city information is not intuitive. It’s called “Locality”. You can get the locality from addresses array as shown in the code.

The above code will also give the viewer’s Orkut profile URL. You can determine the viewer’s profile UID from the URL.

Part 1 | 3 | 4 | 5

Related Posts Plugin for WordPress, Blogger...
Bookmark and Share
Tagged on: , , ,

3 thoughts on “How to Create OpenSocial Application – Part 2

  1. Jill

    Hi Ram,

    Came across this tutorial on creating opensocial application. I would like to ask how can i go about inserting a comment box in a opensocial application for users to drop comments on the particular entry for the day?


Leave a Reply

Your email address will not be published. Required fields are marked *