指定した複数のbit.ly短縮URLがクリックされた数を取得します。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>設置サンプル</title>
<link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
<script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
<body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
<h3>bit.ly API</h3>
<p>指定した複数のbit.ly短縮URLがクリックされた数を取得します。</p>
<div id="loading">loading...</div>
<script type="text/javascript">
/* clicks.phpの中身
<br />
<b>Warning</b>: file_get_contents(http://api.bitly.com/v3/clicks?login=bit.lyのユーザー名&apiKey=bit.lyのAPIキー&shortUrl=http%3A%2F%2Fbitly.com%2FhwYuQv&shortUrl=http%3A%2F%2Fbitly.com%2FGZMtjT&shortUrl=http%3A%2F%2Fbitly.com%2FGPogh7&format=json) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.0 410 Gone
in <b>/home/users/1/lolipop.jp-14d3be2b68bd94/web/module/include/topic/bitlyapi/clicks.inc</b> on line <b>22</b><br />
*/
$(function(){
$.getJSON(
"/module/include/topic/bitlyapi/clicks.php", //短縮URLデコード
null,
function(data){
var s="";
if(window.console && console.log) console.log(data); //debug
$.each(data,function(k,v){
if(k=="data"){
$.each(v,function(k2,v2){
if(k2=="clicks"){
for(var i=0; i<v2.length; i++){
s+="<hr />";
$.each(v2[i],function(k3,v3){
if(k3=="short_url"){
s+=k3+": <a href='"+v3+"' target='_blank'>"+v3+"</a><br>";
}else{
s+=k3+": "+v3+"<br>";
}
});
}
s+="<hr />";
}
});
}else{
s+=k+": "+v+"<br>";
}
});
$("#loading").html(s);
}
);
});
</script>
</body>
</html>