Blog announcement: http://opensocialapis.blogspot.com/
Java code: http://code.google.com/p/opensocial-java-client/
Orkut Sandbox information: http://code.google.com/apis/orkut/docs/rest/developers_guide_protocol.html
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 DisplayProfileData.java example to display all information about a particular person. It will also work in DisplayFriends.java. 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
for(OpenSocialObject compVal : complexValues) {
processFields(compVal);
}
}
}
Call it anywhere after creating the sample person, like so:
OpenSocialPerson person = c.fetchPerson("03067092798963641994");
...
processFields(person);
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:
value http://www.orkut.com/img/i_nophoto64.gif
type thumbnail
thumbnailUrl http://www.orkut.com/img/i_nophoto64.gif
name is complex:
givenName API
familyName DWH
id 03067092798963641994
isOwner false
isViewer true
------Done---------
Thumbnail URL: http://www.orkut.com/img/i_nophoto64.gif
----------
Modifying the Backend
c.setProperty(OpenSocialClient.Properties.CONSUMER_SECRET,
"uynAeXiWTisflWX99KU1D2q5");
c.setProperty(OpenSocialClient.Properties.CONSUMER_KEY,
"orkut.com:623061448914");
c.setProperty(OpenSocialClient.Properties.VIEWER_ID,
"03067092798963641994");
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:
- Write a gadget. You can use http://opensocial-resources.googlecode.com/svn/samples/rest_rpc/sample.xml for example. I'm not sure if the gadget in anyway affects the REST/RPC server side calls that you can use.
- Get an Orkut sandbox account and log into sandbox.orkut.com.
- Install your application into your Orkut account.
- Verify that you own the gadget: https://www.google.com/gadgets/directory/verify
See
http://groups.google.com/group/opensocial-orkut/browse_thread/thread/43640406754ab7f6
No comments:
Post a Comment