実行結果
Twitter JSON APIの使い方
設置サンプルのソース
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="ja" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<title>Twitter JSON APIの使い方 | 設置サンプル</title>
<link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
<!-- JS -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
/* 例1 */
var tweeturl="http://twitter.com/status/user_timeline/cocoism.json?count=5&callback=?";
$.getJSON(tweeturl, function(data){
// JSONデータ読み込み
$.each(data, function(i, item){
// URLにテキストがある場合はリンク設置
var txt = item.text
.replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig,'<a href="$1">$1</a>')
.replace(/@+([_A-Za-z0-9-]+)/ig, '<a href="http://twitter.com/$1">@$1</a>')
.replace(/#+([_A-Za-z0-9-]+)/ig, '<a href="http://search.twitter.com/search?q=$1">#$1</a>');
$("<li></li>")
.addClass(i%2 ? "even" : "odd")
.html(txt)
.prependTo("#tweet");
});
});
});
</script>
<!-- CSS -->
<style type="text/css">
#tweet {
margin:0; padding:0;
list-style:none;
border:1px solid #666;
width:30em;
}
#tweet li {
margin:0; padding:.5em;
list-style:none;
background-color:#fff;
}
#tweet li.odd {
background-color:#ddd;
}
</style>
<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>
<div id="wrap">
<h1>Twitter JSON APIの使い方</h1>
<!-- CODE -->
<ul id="tweet"></ul>
<ul id="tweet2"></ul>
<!-- / CODE -->
</div>
</body>
</html>