- 追加された行はこのように表示されます。
- 削除された行は
このように表示されます。
!!!mixi アプリ VIEWERの情報表示
[mixi アプリ]
!!閲覧者情報の表示サンプル
{{ref_image mixi_app_test01.jpg}}
!!ソース
!重要API
,API,概要
,[newDataRequest|http://code.google.com/intl/ja/apis/opensocial/docs/0.8/reference/#opensocial.DataRequest],コンテナから友だちのデータ、プロフィール、アプリケーション データ、アクティビティなどのソーシャル情報を要求するために使用
,[newFetchPersonRequest|http://code.google.com/intl/ja/apis/opensocial/docs/0.8/reference/#opensocial.DataRequest.newFetchPersonRequest],指定した個人 ID のプロフィールを要求するアイテムを作成。[Person|http://code.google.com/intl/ja/apis/opensocial/docs/0.8/reference/#opensocial.Person] オブジェクトを返す
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="hello world example">
<Require feature="opensocial-0.8"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
<script type="text/javascript">
// 閲覧者情報取得要求
function request() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest("OWNER"), "viewer_data");
req.add(req.newFetchPersonRequest("VIEWER"), "viewer_data");
req.send(response);
}
// 閲覧者情報取得応答
function response(dataResponse) {
var viewer = dataResponse.get("viewer_data").getData();
document.getElementById("viewer_inf").innerHTML
= printPropertiesAsTable(viewer, 0);
}
// 閲覧者情報表示
function printPropertiesAsTable(obj, dpth) {
if (dpth > 5) {
return "<b>parse limit over</b>";
}
var tbl = "<table border='1'>";
tbl += "<tr><th>Property</th><th>Type</th><th>Value</th></tr>";
for (prop in obj) {
var type = typeof(eval("obj." + prop));
var blnkt = (type == "function")?"()":"";
tbl += "<tr>";
tbl += "<td>" + prop + "</td>";
tbl += "<td>" + type + "</td>";
if (type == 'object') {
tbl += "<td>" + printPropertiesAsTable(eval("obj." + prop), dpth++) + "</td>";
} else {
tbl += "<td>" + eval("obj." + prop + blnkt) + "</td>";
}
tbl += "</tr>";
}
tbl += "</table>";
return tbl;
}
gadgets.util.registerOnLoadHandler(request);
</script>
<div id="viewer_inf"/>
]]>
</Content>
</Module>