
どうせならJSONPのgatewayも一緒に用意すればよかったのに。
機能変更、お知らせなど - はてなブックマーク日記 - (開発者さま向け) 特定サイトの被はてなブックマーク数を取得する XML-RPC API の公開についてはてなブックマークカウンターの公開に合わせて、特定サイトの被はてなブックマーク数の合計値を取得する XML-RPC API を公開しました。
というわけで、足りないものはHackする方向で。
とはいえ、404 Blog Not Found:perl - HateBinarySearchみたいな力技が要らなくなったのはいいことですね。
http://blog.livedoor.jp/dankogai/ is bookmarked by users.
見てのとおり、Server側はCGI.pmすら使ってません。CPANモジュールで必要なのはSOAP::Liteに含まれているXMLRPC::Liteだけです。
Server: tcjsonp.cgiClientが受け取るのは、{'uri':'http://www.example.com/', 'count':9}というJSONです。詳しくは以下を参照のこと。
Client:<script> function $(id){ return document.getElementById(id) } if ( typeof(Hatena) == 'undefined' ) Hatena = function() {}; Hatena.TotalCount = function(proxy, cb){ this.proxy = proxy || 'http://www.dan.co.jp/~dankogai/cgi/hatena/tcjsonp.cgi'; this.cb = (cb || 'jsonp'); this.parse = function(uri, cb){ if (! cb) cb = this.cb; var script = document.createElement('script'); script.id = this.proxy + '/' + cb + '/' + uri; script.charset = 'UTF-8'; script.src = script.id; document.lastChild.appendChild(script); // document.lastChild.removeChild(script); }; return this; } var hbtotal = new Hatena.TotalCount('http://www.dan.co.jp/~dankogai/cgi/hatena/tcjsonp.cgi'); function jsonp(json){ //alert(json.uri + ',' + json.count); $('a.uri').setAttribute('href', json.uri); $('a.uri').innerHTML = json.uri; $('b.count').innerHTML = json.count; } </script> <div style="border: dotted 1px; padding: 0.5em"> <input id='uri' type="text" size="64" value="http://blog.livedoor.jp/dankogai/"> <input type="submit" onclick="hbtotal.parse($('uri').value, 'jsonp')"> <p><a id="a.uri" target="_blank" href="http://blog.livedoor.jp/dankogai/">http://blog.livedoor.jp/dankogai/</a> is bookmarked by <b id="b.count"></b> users. </p> </div>
Enjoy!
Dan the Javascripting Perl Monger
このブログにコメントするにはログインが必要です。
さんログアウト
この記事には許可ユーザしかコメントができません。