指定したユーザーの公式RT含まない最新のツイートを20件(1ページ分)取得します。
<!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 REST API:タイムライン関連:user_timeline(指定したユーザーのタイムラインを取得) | 設置サンプル</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <script type="text/javascript" src="/content/lib/jquery/jquery.jsonp.js"></script> <!-- JS --> <script type="text/javascript"> $(function(){ var url="http://api.twitter.com/1/statuses/user_timeline.json?user_id=7948862&page=1&callback={callback}"; $.getJSONP(url, function(json){ var s=""; for(var i in json){ s+="<li>"; s+="<a href='http://twitter.com/#!/"+json[i].user.screen_name+"' class='prof'><img src='"+json[i].user.profile_image_url+"' /></a>"; s+="<div>"; s+="<p class='tweet'>"+formatTwitterString(json[i].text)+"</p>"; s+="<p><a href='https://twitter.com/#!/"+json[i].user.screen_name+"/status/"+json[i].id_str+"'>"+relativeTime(json[i].created_at)+"</a> "+json[i].source+"から</p>"; s+="</div>"; s+="</li>"; } $("#recent").html("<ul>"+s+"</ul>"); }); }); // リンク内につぶやきを含むURLに変更 function formatTwitterString(str){ str = str.replace(/((ftp|http|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>'); str = str.replace(/@(\w+)/gm,'<a href="http://twitter.com/$1" target="_blank">@$1</a>'); str = str.replace(/#(\w+)/gm,'<a href="http://search.twitter.com/search?q=$1" target="_blank">#$1</a>'); return str; } function relativeTime(pastTime){ var origStamp = Date.parse(pastTime); var curDate = new Date(); var currentStamp = curDate.getTime(); var difference = parseInt((currentStamp - origStamp)/1000); if(difference < 0) return false; if(difference <= 5) return "いまさっき"; if(difference <= 20) return "数秒前"; if(difference <= 60) return "1分以内"; if(difference < 3600) return parseInt(difference/60)+" 分前"; if(difference <= 1.5*3600) return "1時間前"; if(difference < 23.5*3600) return Math.round(difference/3600)+" 時間前"; if(difference < 1.5*24*3600) return "1日前"; var dateArr = pastTime.split(' '); return (parseInt(difference / 86400)).toString() + '日前'; } </script> <style type="text/css"> #recent div { font-size:80%; color: } #recent ul { list-style:none; border-top:1px dotted #ccc; margin:0; padding:0; } #recent li { border-bottom:1px dotted #ccc; list-style:none; clear:both; overflow:hidden; margin:0; padding:5px 0; } #recent a.prof { float:left; width:48px; height:48px; overflow:hidden; margin:0; padding:3px 0; } #recent p { margin:0; padding:0; } #recent div { margin:0 0 0 58px; padding:0; } #recent p.footer, #recent p.rt { color:#666; margin-top:5px; } #recent p.rt { background:transparent url(/content/img/topic/twitter/rt.gif) no-repeat 0 0; overflow:hidden; padding-left:16px; min-height:15px; height:auto!important; height:15px; } </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 REST API:タイムライン関連:user_timeline(指定したユーザーのタイムラインを取得) | 設置サンプル</h1> <p>指定したユーザーの公式RT含まない最新のツイートを20件(1ページ分)取得します。</p> <!-- CODE --> <div id="recent"></div> <!-- / CODE --> </div> </body> </html>