指定したユーザーのお気に入りを最大100件表示します。
スクリーンネーム:@<!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 RES API:お気に入り関連:favorites(認証ユーザーまたは指定したユーザーIDのお気に入りを取得)| 設置サンプル</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.3.2/jquery.min.js"></script>
<script type="text/javascript" src="/content/lib/jquery/jquery.jsonp.js"></script>
<!-- JS -->
<script type="text/javascript">
$(function(){
$("#btn").bind("click",function(){
$obj=$("#res");
var _screenname=$("#screenname").val();
if(!_screenname){
$obj.html("<p>※スクリーンネームを入力してください</p>");
return;
}else{
$obj.html("<p>Loading...</p>");
}
var url="http://twitter.com/favorites.json?id="+_screenname+"&count=100&callback={callback}";
$.getJSONP(url, function(json){
var s="";
$.each(json, function(i, item){
if(!item) return;
s+="<li class='corner'><b></b><i>★</i>";
s+="<a href='http://twitter.com/"+item.user.screen_name+"' target='_blank'><img src='"+item.user.profile_image_url+"' /></a>";
s+=formatStr(item.text);
s+="<div>";
s+="<span><a href='http://twitter.com/"+item.user.screen_name+"/status/"+item.id+"' target='_blank'>"+relativeTime(item.created_at)+"</a></span>";
s+="<span>"+item.source+"</span>";
s+="</div>";
s+="</li>";
});
$("#res").html("<h2>@"+_screenname+"のお気に入り</h2><ul>"+s+"</ul>");
});
});
$("#btn").click();
});
function formatStr(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 < 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">
#res ul { margin:0; padding:0; list-style:none; border-top:1px solid #ccc; }
#res li { background-color:#fff; margin:0; padding:10px 50px 10px 62px; list-style:none; display:block; position:relative; min-height:42px; height:auto!important; height:42px; font-size:13px; border-bottom:1px solid #ccc; }
#res li:hover { background-color:#d3f7ff; }
#res li img { display:block; width:32px; height:32px; margin:0; padding:1px; outline:1px solid #ccc; background:#fff; position:absolute; top:10px; left:10px; }
#res li div { margin:5px 0; padding:0; font-size:11px; }
#res li div span { margin:0 10px 0 0; padding:0; }
/* ★ */
.corner {
position:relative;
}
.corner b {
position:absolute;
top:0; right:0;
width:40px; height:auto;
border-top: 40px solid darkorange;
border-left: 40px solid transparent;
display:block;
width: 0; height: 0;
}
.corner i {
position:absolute;
top:0; right:0;
font-style:normal;
display:block;
color:#fff;
padding:5px;
}
</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:お気に入り関連:favorites(認証ユーザーまたは指定したユーザーIDのお気に入りを取得)| 設置サンプル</h1>
<p>指定したユーザーのお気に入りを最大100件表示します。</p>
<!-- CODE -->
スクリーンネーム:@<input type="text" id="screenname" value="cocoism" />
<input type="button" id="btn" value="取得" />
<div id="res"></div>
<!-- / CODE -->
</div>
</body>
</html>