Twitter関連Twitter REST API:お気に入り関連
- favorites〔お気に入りを取得(ユーザーを指定しない場合は要認証)〕
- favorites/create/:id〔指定したつぶやきIDを認証ユーザーのお気に入りに追加(要認証)〕
- favorites/destroy/:id〔指定したつぶやきIDを認証ユーザーのお気に入りから削除(要認証)〕
favorites
お気に入りを取得(ユーザーを指定しない場合は要認証)
2009/7/18
![]()
![]()
http://api.twitter.com/1/favorites.[xml|json|rss|atom]
パラメータを指定しない場合は、認証ユーザーの最新のお気に入り20件取得します(要認証)。 「id」パラメータにスクリーンネームまたはユーザーIDを指定した場合は、そのユーザーの最新のお気に入り20件を取得します(認証不要)。
パラメーター
| パラメーター | 説明 | |
|---|---|---|
| id | 任意 |
お気に入りを取得するユーザーのユーザーIDまたはスクリーンネームを指定。 例)http://api.twitter.com/1/favorites/7948862.xml 例)http://api.twitter.com/1/favorites.xml?id=7948862 例)http://api.twitter.com/1/favorites/cocoism.xml 例)http://api.twitter.com/1/favorites.xml?id=cocoism |
| page | 任意 |
指定したページ番号(1ページ20件)のお気に入りを取得したい場合に使用。 例)http://api.twitter.com/1/favorites.xml?page=3 |
| since_id | 任意 |
指定したリストIDより後のお気に入りを取得したい場合に使用。 例)http://api.twitter.com/1/favorites.xml?since_id=12345 |
| include_entities | 任意 |
ステータス情報に'entities'を含める場合は、true,t,1のいずれかを指定。 例)http://api.twitter.com/1/favorites.xml?include_entities=1 |
取得サンプル(XML/JSON)
favorites.xml
<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
<status>
<created_at>Thu May 26 11:09:13 +0000 2011</created_at>
<id>73707254221770752</id>
<text>ハーゲンダッツのクレープグラッセ食べたーい♥</text>
<source><a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a></source>
<truncated>false</truncated>
<favorited>true</favorited>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<in_reply_to_screen_name></in_reply_to_screen_name>
<retweet_count>0</retweet_count>
<retweeted>false</retweeted>
<user>
<id>7948862</id>
<name>つんつ</name>
<screen_name>cocoism</screen_name>
<location>カワタマ or オモサン</location>
<description>青山でWeb系のお仕事してます。デザイナーズレストランははるか昔に卒業済。芋焼酎と焼鳥が大好きで居心地のいい呑み屋でおやじ談義するのがライフワーク。最近は日本酒をお勉強中。家では大人しく猛犬チワワのママしてます。iPhone4/Xperia所有。</description>
<profile_image_url>http://a0.twimg.com/profile_images/1202496271/usa_normal.png</profile_image_url>
<url>http://phpjavascriptroom.com/</url>
<protected>false</protected>
<followers_count>612</followers_count>
<profile_background_color>8350a1</profile_background_color>
<profile_text_color>ff6699</profile_text_color>
<profile_link_color>f2afcf</profile_link_color>
<profile_sidebar_fill_color>8350a1</profile_sidebar_fill_color>
<profile_sidebar_border_color>8350a1</profile_sidebar_border_color>
<friends_count>534</friends_count>
<created_at>Sat Aug 04 05:52:33 +0000 2007</created_at>
<favourites_count>443</favourites_count>
<utc_offset>32400</utc_offset>
<time_zone>Tokyo</time_zone>
<profile_background_image_url>http://a1.twimg.com/profile_background_images/187449144/02.png</profile_background_image_url>
<profile_background_tile>true</profile_background_tile>
<profile_use_background_image>true</profile_use_background_image>
<notifications>false</notifications>
<geo_enabled>true</geo_enabled>
<verified>false</verified>
<following>false</following>
<statuses_count>5019</statuses_count>
<lang>ja</lang>
<contributors_enabled>false</contributors_enabled>
<follow_request_sent>false</follow_request_sent>
<listed_count>52</listed_count>
<show_all_inline_media>true</show_all_inline_media>
<default_profile>false</default_profile>
<default_profile_image>false</default_profile_image>
<is_translator>false</is_translator>
</user>
<geo/>
<coordinates/>
<place/>
<contributors/>
</status>
…略…
</statuses>
favorites.json
json[0]['in_reply_to_status_id_str']= json[0]['retweet_count']=0 json[0]['truncated']= json[0]['user']['show_all_inline_media']=1 json[0]['user']['geo_enabled']=1 json[0]['user']['notifications']= json[0]['user']['profile_background_color']=8350a1 json[0]['user']['protected']= json[0]['user']['profile_image_url']=http://a0.twimg.com/profile_images/1202496271/usa_normal.png json[0]['user']['profile_background_image_url']=http://a1.twimg.com/profile_background_images/187449144/02.png json[0]['user']['location']=カワタマ or オモサン json[0]['user']['name']=つんつ json[0]['user']['listed_count']=52 json[0]['user']['screen_name']=cocoism json[0]['user']['id_str']=7948862 json[0]['user']['statuses_count']=5019 json[0]['user']['utc_offset']=32400 json[0]['user']['profile_text_color']=ff6699 json[0]['user']['url']=http://phpjavascriptroom.com/ json[0]['user']['verified']= json[0]['user']['profile_sidebar_fill_color']=8350a1 json[0]['user']['description']=青山でWeb系のお仕事してます。デザイナーズレストランははるか昔に卒業済。芋焼酎と焼鳥が大好きで居心地のいい呑み屋でおやじ談義するのがライフワーク。最近は日本酒をお勉強中。家では大人しく猛犬チワワのママしてます。iPhone4/Xperia所有。 json[0]['user']['default_profile']= json[0]['user']['lang']=ja json[0]['user']['profile_background_tile']=1 json[0]['user']['created_at']=Sat Aug 04 05:52:33 +0000 2007 json[0]['user']['default_profile_image']= json[0]['user']['friends_count']=534 json[0]['user']['profile_link_color']=f2afcf json[0]['user']['id']=7948862 json[0]['user']['is_translator']= json[0]['user']['favourites_count']=443 json[0]['user']['profile_sidebar_border_color']=8350a1 json[0]['user']['follow_request_sent']= json[0]['user']['contributors_enabled']= json[0]['user']['time_zone']=Tokyo json[0]['user']['following']= json[0]['user']['profile_use_background_image']=1 json[0]['user']['followers_count']=612 json[0]['in_reply_to_screen_name']= json[0]['in_reply_to_user_id_str']= json[0]['id_str']=73707254221770752 json[0]['contributors']= json[0]['retweeted']= json[0]['in_reply_to_status_id']= json[0]['text']=ハーゲンダッツのクレープグラッセ食べたーい♥ json[0]['created_at']=Thu May 26 11:09:13 +0000 2011 json[0]['place']= json[0]['in_reply_to_user_id']= json[0]['id']=7.37072542218E+16 json[0]['coordinates']= json[0]['geo']= json[0]['source']=HootSuite json[0]['favorited']=1 …略…
設置サンプル
指定したユーザーのお気に入りを最大100件取得して表示します。
右上の★マークはCSSで付けています(参考:ShapesOfCSS)。

設置サンプルサンプルを見る
<!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>
</head>
<body>
<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>
favorites/create/:id
指定したつぶやきIDを認証ユーザーのお気に入りに追加(要認証)
2009/7/18
![]()
![]()
http://api.twitter.com/1/favorites/create/[ツイートID].[xml|json]
指定したツイートIDを認証ユーザーのお気に入りに追加します。 成功した場合に、お気に入りに追加したツイート情報を返します。
パラメーター
| パラメーター | 説明 | |
|---|---|---|
| id | 必須 |
お気に入りに追加するつぶやきIDを指定。 例)http://api.twitter.com/1/favorites/create/2567482373.xml |
| include_entities | 任意 |
ステータス情報に'entities'を含める場合は、true,t,1のいずれかを指定。 例)http://api.twitter.com/1/favorites/create/2567482373.xml?include_entities=1 |
取得サンプル(XML/JSON)
create.xml
▼成功した場合
<?xml version="1.0" encoding="UTF-8"?>
<status>
<created_at>Thu May 26 13:58:56 +0000 2011</created_at>
<id>73749964697763840</id>
<text>ジョーズいいねぇ。お茶がサバイバルになりそう♪ - 14 Modern and Stylish Tea Infuser and Tea Strainer – DesignSwan.com http://ow.ly/53xyJ</text>
<source><a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a></source>
<truncated>false</truncated>
<favorited>true</favorited>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<in_reply_to_screen_name></in_reply_to_screen_name>
<retweet_count>0</retweet_count>
<retweeted>false</retweeted>
<user>
<id>7948862</id>
<name>つんつ</name>
<screen_name>cocoism</screen_name>
<location>カワタマ or オモサン</location>
<description>青山でWeb系のお仕事してます。デザイナーズレストランははるか昔に卒業済。芋焼酎と焼鳥が大好きで居心地のいい呑み屋でおやじ談義するのがライフワーク。最近は日本酒をお勉強中。家では大人しく猛犬チワワのママしてます。iPhone4/Xperia所有。</description>
<profile_image_url>http://a0.twimg.com/profile_images/1202496271/usa_normal.png</profile_image_url>
<url>http://phpjavascriptroom.com/</url>
<protected>false</protected>
<followers_count>612</followers_count>
<profile_background_color>8350a1</profile_background_color>
<profile_text_color>ff6699</profile_text_color>
<profile_link_color>f2afcf</profile_link_color>
<profile_sidebar_fill_color>8350a1</profile_sidebar_fill_color>
<profile_sidebar_border_color>8350a1</profile_sidebar_border_color>
<friends_count>534</friends_count>
<created_at>Sat Aug 04 05:52:33 +0000 2007</created_at>
<favourites_count>443</favourites_count>
<utc_offset>32400</utc_offset>
<time_zone>Tokyo</time_zone>
<profile_background_image_url>http://a1.twimg.com/profile_background_images/187449144/02.png</profile_background_image_url>
<profile_background_tile>true</profile_background_tile>
<profile_use_background_image>true</profile_use_background_image>
<notifications>false</notifications>
<geo_enabled>true</geo_enabled>
<verified>false</verified>
<following>false</following>
<statuses_count>5019</statuses_count>
<lang>ja</lang>
<contributors_enabled>false</contributors_enabled>
<follow_request_sent>false</follow_request_sent>
<listed_count>52</listed_count>
<show_all_inline_media>true</show_all_inline_media>
<default_profile>false</default_profile>
<default_profile_image>false</default_profile_image>
<is_translator>false</is_translator>
</user>
<geo/>
<coordinates/>
<place/>
<contributors/>
</status>
▼失敗した場合(既にお気に入りに登録済の場合)
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<error>既にお気に入りに登録しています。</error>
<request>/1/favorites/create/73749964697763840.xml</request>
</hash>
create.json
▼成功した場合 json[in_reply_to_status_id_str]= json[retweet_count]=0 json[truncated]= json[user]['notifications']= json[user]['profile_background_color']=8350a1 json[user]['protected']= json[user]['profile_image_url']=http://a0.twimg.com/profile_images/1202496271/usa_normal.png json[user]['default_profile_image']= json[user]['profile_background_image_url']=http://a1.twimg.com/profile_background_images/187449144/02.png json[user]['location']=カワタマ or オモサン json[user]['name']=つんつ json[user]['screen_name']=cocoism json[user]['id_str']=7948862 json[user]['is_translator']= json[user]['utc_offset']=32400 json[user]['profile_text_color']=ff6699 json[user]['url']=http://phpjavascriptroom.com/ json[user]['follow_request_sent']= json[user]['verified']= json[user]['friends_count']=534 json[user]['profile_sidebar_fill_color']=8350a1 json[user]['description']=青山でWeb系のお仕事してます。デザイナーズレストランははるか昔に卒業済。芋焼酎と焼鳥が大好きで居心地のいい呑み屋でおやじ談義するのがライフワーク。最近は日本酒をお勉強中。家では大人しく猛犬チワワのママしてます。iPhone4/Xperia所有。 json[user]['lang']=ja json[user]['profile_background_tile']=1 json[user]['created_at']=Sat Aug 04 05:52:33 +0000 2007 json[user]['contributors_enabled']= json[user]['show_all_inline_media']=1 json[user]['geo_enabled']=1 json[user]['profile_link_color']=f2afcf json[user]['id']=7948862 json[user]['listed_count']=52 json[user]['favourites_count']=443 json[user]['profile_sidebar_border_color']=8350a1 json[user]['default_profile']= json[user]['time_zone']=Tokyo json[user]['statuses_count']=5019 json[user]['following']= json[user]['profile_use_background_image']=1 json[user]['followers_count']=612 json[in_reply_to_screen_name]= json[in_reply_to_user_id_str]= json[id_str]=73749964697763840 json[contributors]= json[retweeted]= json[in_reply_to_status_id]= json[text]=ジョーズいいねぇ。お茶がサバイバルになりそう♪ - 14 Modern and Stylish Tea Infuser and Tea Strainer – DesignSwan.com http://ow.ly/53xyJ json[created_at]=Thu May 26 13:58:56 +0000 2011 json[place]= json[in_reply_to_user_id]= json[id]=7.37499646978E+16 json[coordinates]= json[geo]= json[source]=HootSuite json[favorited]=1 ▼失敗した場合(既にお気に入りに登録済の場合) json[error]=既にお気に入りに登録しています。 json[request]=/1/favorites/create/73749964697763840.json
favorites/destroy/:id
指定したつぶやきIDを認証ユーザーのお気に入りから削除(要認証)
2009/7/18
![]()
![]()
http://api.twitter.com/version/favorites/destroy/[ツイートID].[xml|json]
指定したツイートを認証ユーザーのお気に入りから解除します。 成功した場合に、お気に入りから解除したツイート情報を返します。 お気に入りに登録していないツイートを解除してもエラーにはなりません。
パラメーター
| パラメーター | 説明 | |
|---|---|---|
| id | 必須 |
お気に入りから削除するつぶやきIDを指定。 例)http://api.twitter.com/version/favorites/destroy/2567482373.xml |
取得サンプル(XML/JSON)
destroy.xml
▼成功した場合
<?xml version="1.0" encoding="UTF-8"?>
<status>
<created_at>Thu May 26 13:58:56 +0000 2011</created_at>
<id>73749964697763840</id>
<text>ジョーズいいねぇ。お茶がサバイバルになりそう♪ - 14 Modern and Stylish Tea Infuser and Tea Strainer – DesignSwan.com http://ow.ly/53xyJ</text>
<source><a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a></source>
<truncated>false</truncated>
<favorited>false</favorited>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<in_reply_to_screen_name></in_reply_to_screen_name>
<retweet_count>0</retweet_count>
<retweeted>false</retweeted>
<user>
<id>7948862</id>
<name>つんつ</name>
<screen_name>cocoism</screen_name>
<location>カワタマ or オモサン</location>
<description>青山でWeb系のお仕事してます。デザイナーズレストランははるか昔に卒業済。芋焼酎と焼鳥が大好きで居心地のいい呑み屋でおやじ談義するのがライフワーク。最近は日本酒をお勉強中。家では大人しく猛犬チワワのママしてます。iPhone4/Xperia所有。</description>
<profile_image_url>http://a0.twimg.com/profile_images/1202496271/usa_normal.png</profile_image_url>
<url>http://phpjavascriptroom.com/</url>
<protected>false</protected>
<followers_count>611</followers_count>
<profile_background_color>8350a1</profile_background_color>
<profile_text_color>ff6699</profile_text_color>
<profile_link_color>f2afcf</profile_link_color>
<profile_sidebar_fill_color>8350a1</profile_sidebar_fill_color>
<profile_sidebar_border_color>8350a1</profile_sidebar_border_color>
<friends_count>534</friends_count>
<created_at>Sat Aug 04 05:52:33 +0000 2007</created_at>
<favourites_count>442</favourites_count>
<utc_offset>32400</utc_offset>
<time_zone>Tokyo</time_zone>
<profile_background_image_url>http://a1.twimg.com/profile_background_images/187449144/02.png</profile_background_image_url>
<profile_background_tile>true</profile_background_tile>
<profile_use_background_image>true</profile_use_background_image>
<notifications>false</notifications>
<geo_enabled>true</geo_enabled>
<verified>false</verified>
<following>true</following>
<statuses_count>5019</statuses_count>
<lang>ja</lang>
<contributors_enabled>false</contributors_enabled>
<follow_request_sent>false</follow_request_sent>
<listed_count>51</listed_count>
<show_all_inline_media>true</show_all_inline_media>
<default_profile>false</default_profile>
<default_profile_image>false</default_profile_image>
<is_translator>false</is_translator>
</user>
<geo/>
<coordinates/>
<place/>
<contributors/>
</status>
destroy.json
▼成功した場合 json[in_reply_to_screen_name]= json[in_reply_to_user_id_str]= json[user]['profile_background_color']=8350a1 json[user]['protected']= json[user]['default_profile_image']= json[user]['profile_background_image_url']=http://a1.twimg.com/profile_background_images/187449144/02.png json[user]['followers_count']=611 json[user]['location']=カワタマ or オモサン json[user]['name']=つんつ json[user]['default_profile']= json[user]['notifications']= json[user]['profile_image_url']=http://a0.twimg.com/profile_images/1202496271/usa_normal.png json[user]['id_str']=7948862 json[user]['is_translator']= json[user]['utc_offset']=32400 json[user]['profile_text_color']=ff6699 json[user]['url']=http://phpjavascriptroom.com/ json[user]['follow_request_sent']= json[user]['friends_count']=534 json[user]['profile_sidebar_fill_color']=8350a1 json[user]['description']=青山でWeb系のお仕事してます。デザイナーズレストランははるか昔に卒業済。芋焼酎と焼鳥が大好きで居心地のいい呑み屋でおやじ談義するのがライフワーク。最近は日本酒をお勉強中。家では大人しく猛犬チワワのママしてます。iPhone4/Xperia所有。 json[user]['screen_name']=cocoism json[user]['lang']=ja json[user]['profile_background_tile']=1 json[user]['created_at']=Sat Aug 04 05:52:33 +0000 2007 json[user]['contributors_enabled']= json[user]['verified']= json[user]['show_all_inline_media']=1 json[user]['geo_enabled']=1 json[user]['favourites_count']=442 json[user]['profile_link_color']=f2afcf json[user]['id']=7948862 json[user]['listed_count']=51 json[user]['profile_sidebar_border_color']=8350a1 json[user]['time_zone']=Tokyo json[user]['statuses_count']=5019 json[user]['following']= json[user]['profile_use_background_image']=1 json[contributors]= json[retweeted]= json[truncated]= json[id_str]=73749964697763840 json[text]=ジョーズいいねぇ。お茶がサバイバルになりそう♪ - 14 Modern and Stylish Tea Infuser and Tea Strainer – DesignSwan.com http://ow.ly/53xyJ json[in_reply_to_status_id]= json[created_at]=Thu May 26 13:58:56 +0000 2011 json[place]= json[in_reply_to_user_id]= json[id]=7.37499646978E+16 json[source]=HootSuite json[favorited]= json[in_reply_to_status_id_str]= json[coordinates]= json[geo]= json[retweet_count]=0