JavaScript API

opensocial.* 名前空間のたくさんのインターフェース(空のメソッド)が定義され、ドキュメント化されているので、それを実装する。例:http://opensocial-resources.googlecode.com/svn/spec/0.8/opensocial/person.js

/**
 * Gets data for this person that is associated with the specified key.
 *
 * @param {String} key The key to get data for;
 *    keys are defined in <a href="opensocial.Person.Field.html"><code>
 *    Person.Field</code></a>
 * @param {Map.&lt;opensocial.DataRequest.DataRequestFields, Object&gt;}
 *  opt_params Additional
 *    <a href="opensocial.DataRequest.DataRequestFields.html">params</a>
 *    to pass to the request.
 * @return {String} The data
 */
opensocial.Person.prototype.getField = function(key, opt_params) {};

という感じで、定義されているので、OpenSocial Container 内では

var me = new opensocial.Person();
alert(me.getField(opensocial.Person.Field.NAME));

といったJavaScriptが動作する、ということ。参照実装のApache Shindig では、

opensocial.Person.prototype.getField = function(key, opt_params) {
  return opensocial.Container.getField(this.fields_, key, opt_params);
};

といった実装が記述されている。と、、v0.8.1*1のSpecでは

Methods may return the error code opensocial.ResponseItem.NOT_IMPLEMENTED for a specific method if the container does not support a specific request. No additional public methods or classes may be put on the OpenSocial namespace at any level. The required methods and fields are defined in the following JavaScript files:

となっていて、opensocial.Container なんていうクラス、Specにないんだけど?、と思ったら、v0.9*2 だと、この文章

Methods may return the error code opensocial.ResponseItem.NOT_IMPLEMENTED for a specific method if the container does not support a specific request.

と、namespace/class/methods の拡張の制約が消されているwww なんでこう、最初から選んだサンプルで罠にはまる性分なんだろう。。