Thursday, January 08, 2009

OpenSocial REST API Is Here

I just noticed the Google-led OpenSocial REST/RPC APIs are finally available. These allow you to build Java, PHP, Python, and Ruby clients that can access and manipulate your social network data.

Blog announcement:

Java code:

Orkut Sandbox information:

Client Examples
As you might expect, you can use Orkut's sandbox as your "backend" service. The Java code and examples are pretty simple but work. As a bonus, here is a recursive method that you can use in the example to display all information about a particular person. It will also work in You'll need to add imports for OpenSocialObject and OpenSocialField.

protected void processFields(OpenSocialObject osObj) throws Exception {
//See all fields
String[] fields=osObj.fieldNames();
for(String fieldName : fields) {
OpenSocialField afield=osObj.getField(fieldName);
if(!afield.isComplex()) {
System.out.println(fieldName+" "+afield.getStringValue());
else {
System.out.println(fieldName+" is complex:" );
Collection complexValues=afield.getValues();
for(OpenSocialObject compVal : complexValues) {

Call it anywhere after creating the sample person, like so:

OpenSocialPerson person = c.fetchPerson("03067092798963641994");

You may also want to change the Person ID in the above line. You get this ID when you add sample.xml social gadget to your sandbox. Mine, for example, is 08354253340777199997. This ID does not need to match the viewer ID discussed below.

Here is the sample output:
156-56-104-143:java mpierce$ java -classpath samples/bin:$CP DisplayProfileData
Info. for API DWH
ID: 03067092798963641994
Printing fields
photos is complex:
type thumbnail
name is complex:
givenName API
familyName DWH
id 03067092798963641994
isOwner false
isViewer true
Thumbnail URL:

Modifying the Backend
Here's were the problems start. The sample clients above include a default view ID, consumer secret, and consumer key as part of the OAuth infrastructure:


Of course you will want to replace these with your own values. To do this, you will need to deploy a gadget and verify that you own it. The steps are simple:
  1. Write a gadget. You can use for example. I'm not sure if the gadget in anyway affects the REST/RPC server side calls that you can use.
  2. Get an Orkut sandbox account and log into
  3. Install your application into your Orkut account.
  4. Verify that you own the gadget:
This last step is the problem. It involves two steps. First you provide the URL for your gadget and submit. You will receive a long signature string, which you need to add to your gadget. Replace the one in the sample.xml if you are using a copy of that. Save your gadget and click the verification web site button to complete the process. Presumably this will give you the consumer key and consumer secret that you need, but I have not gotten this to work for some reason.

No comments: