friendships/exists Twitter API サンプル
friendships/existsのサンプルを作ってみた。
このメソッドは指定した2ユーザの間の friend 関係を調べる。
ってことで早速元ライブドア社長とのfriend 関係を調べるサンプルを
作ってみた。
$person1 = ‘AP_chan’;
$person2 = ‘takapon_jp’;
$url = ‘http://twitter.com/friendships/exists’;
$format = ‘xml’;
$persons12 = make_request($url.’.’.$format.’?user_a=’.$person1.’&user_b=’.$person2);
$result = get_match(’/<friends>(.*)<\/friends>/isU’,$persons12);
echo ‘<p>私達<b>’.$person1.’</b>と<b>’.$person2.’</b>は友達ですか?’.’ | 答えは・・・<b>’.$result.’</b></p>’;
function make_request($url) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/* gets the match */
function get_match($regex,$content)
{
preg_match($regex,$content,$matches);
return $matches[1];
}
?>
こんな感じで、簡単に表示できた。
デモ はこちら
参照はコチラ
11月 9th, 2009 by take | No Comments »
