「Mixi アプリ VIEWERの情報表示」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==mixi アプリ VIEWERの情報表示== [mixi アプリ] ===閲覧者情報の表示サンプル=== File:0801_mixi_app_test01.jpg ===ソース=== ====重要API=…」) |
|||
| 1行目: | 1行目: | ||
==mixi アプリ VIEWERの情報表示== | ==mixi アプリ VIEWERの情報表示== | ||
| − | [mixi アプリ] | + | [[mixi アプリ]] |
===閲覧者情報の表示サンプル=== | ===閲覧者情報の表示サンプル=== | ||
[[File:0801_mixi_app_test01.jpg]] | [[File:0801_mixi_app_test01.jpg]] | ||
| 16行目: | 16行目: | ||
|- | |- | ||
|} | |} | ||
| − | + | <?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() { | function request() { | ||
| 38行目: | 38行目: | ||
// 閲覧者情報表示 | // 閲覧者情報表示 | ||
function printPropertiesAsTable(obj, dpth) { | function printPropertiesAsTable(obj, dpth) { | ||
| − | if (dpth | + | if (dpth > 5) { |
| − | return " | + | return "<b>parse limit over</b>"; |
} | } | ||
| − | var tbl = " | + | var tbl = "<table border='1'>"; |
| − | tbl += " | + | tbl += "<tr><th>Property</th><th>Type</th><th>Value</th></tr>"; |
for (prop in obj) { | for (prop in obj) { | ||
var type = typeof(eval("obj." + prop)); | var type = typeof(eval("obj." + prop)); | ||
var blnkt = (type == "function")?"()":""; | var blnkt = (type == "function")?"()":""; | ||
| − | tbl += " | + | tbl += "<tr>"; |
| − | tbl += " | + | tbl += "<td>" + prop + "</td>"; |
| − | tbl += " | + | tbl += "<td>" + type + "</td>"; |
if (type == 'object') { | if (type == 'object') { | ||
| − | tbl += " | + | tbl += "<td>" + printPropertiesAsTable(eval("obj." + prop), dpth++) + "</td>"; |
} else { | } else { | ||
| − | tbl += " | + | tbl += "<td>" + eval("obj." + prop + blnkt) + "</td>"; |
} | } | ||
| − | tbl += " | + | tbl += "</tr>"; |
} | } | ||
| − | tbl += " | + | tbl += "</table>"; |
return tbl; | return tbl; | ||
} | } | ||
gadgets.util.registerOnLoadHandler(request); | gadgets.util.registerOnLoadHandler(request); | ||
| − | + | </script> | |
| − | + | <div id="viewer_inf"/> | |
| − | ]] | + | ]]> |
| − | + | </Content> | |
| − | + | </Module> | |
2020年2月15日 (土) 08:04時点における版
mixi アプリ VIEWERの情報表示
閲覧者情報の表示サンプル
ソース
重要API
| API | 概要 |
|---|---|
| newDataRequest | コンテナから友だちのデータ、プロフィール、アプリケーション データ、アクティビティなどのソーシャル情報を要求するために使用 |
| http://code.google.com/intl/ja/apis/opensocial/docs/0.8/reference/#opensocial.DataRequest.newFetchPersonRequest] | 指定した個人 ID のプロフィールを要求するアイテムを作成。[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("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>
© 2006 矢木浩人
