friendships/exists Twitter API サンプル

friendships/existsのサンプルを作ってみた。
このメソッドは指定した2ユーザの間の friend 関係を調べる。

ってことで早速元ライブドア社長とのfriend 関係を調べるサンプルを
作ってみた。

<?php

$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 »

PHPとTwitter apiでアプリを作ってみる。

まずはTwitterへの登録が必要みたい。
※APIを使用するにはメールアドレスとパスワードが必要。

早速 サンプル用Twitterを登録してみる。

まずは簡単に表示できるかチェックしてみようってことで、
Twitter 仕様書を参考にPHPで作ってみた。

Twitter APIのサンプル

サンプルコードはコチラから

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<title>Twitter API サンプル</title>
</head>
<body>
<h1>Twitter API サンプル</h1>
<?php

//ユーザーIDとパスワードの設定
$email = “登録メールアドレス“;
$password = “登録パスワード“;

$host = “http://twitter.com/statuses/public_timeline.xml”;
$host .= “?since=”.urlencode(date(’D, d M Y G:i:s GMT’, strtotime(’-10 day’)));
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, “$email:$password”);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

$result = curl_exec($ch);
curl_close($ch);
$XML = simplexml_load_string($result);

echo “<ul>”;
foreach ($XML->status as $status){
echo “<li><b style=\”color:red;\”>”.$status->user->screen_name.”</b>: “.$status->text.”</li><hr>\n”;
}
echo “</ul>”;

?>
<p>powerd by <a href=”http://apiwiki.twitter.com/”>Twitter API</a></p>
</body>

</html>

こんな感じで、公開している名前とツイートを簡単に表示できた。
最新の表示はコチラ

11月 6th, 2009 by take | No Comments »

設置まで8分!簡単なPHPとjQueryを使ったAJAXの投票CGI

AJAX User Poll Using jQuery and PHP

サンプルがなかったので、実際に使ってみた。

思ったより簡単に設置できた。

ポイントはデータベースの設定だけかな?
①解凍して出てくるpolls.sqlを自分のデータベースにインポートする。
②解凍して出てくるpoll.php(下記を見てね)の赤字の部分を自分のデータベースに変更する
③ネットサーバーに[index.html][ style.css][poll.php] [js/jquery-1.3.2.js]をアップ

これだけで完了。
カスタマイズがしやすいので、いろんなところで使えそう。

poll.php
<?php
//Update database information according to your server settings
$conn=mysql_connect(’localhost’, ‘root‘, ‘password‘) or die(”Can’t connect to mysql host”);
//Select the database to use
mysql_select_db(’polls‘) or die(”Can’t connect to DB”);
if(!$_POST['poll'] || !$_POST['pollid']){
$query=mysql_query(”SELECT id, ques FROM questions ORDER BY id DESC LIMIT 1″);
while($row=mysql_fetch_assoc($query)){

同一IPからの時間設定があるので一定の時間内で投票をする場合の重複を禁止している。

10月 20th, 2009 by take | No Comments »

戦闘力がたった26のクズサイト・・・

まだまだできたてのこのサイトなんですが、
まさかこんだけクズ判定されるとは・・・

26のクズサイト

Web スカウター

だいぶ前からあるツールなんだけど、ねんのため

サイトの判断基準にはGoogleのページランクをはじめ、はてなブックマークやdel.icio.usなどのソーシャルブックマークへの登録数、livedoor ReaderなどRSSリーダーでの購読数などを元に、独自の指標で各サイトの影響力をポイント化。

せめて1000ぐらいには持っていきたいと思います。

一度は自分のサイトの戦闘力を測ってみるのも面白いかも?

10月 16th, 2009 by take | No Comments »

あなたのデザインを強化する30の衝撃的なフォント

あなたのデザインを強化する30の衝撃的なフリーフォントの紹介。

衝撃的なフォント

instantShift

基本的にアルファベットのみとなりますが、ここぞというときのインパクトや、
全体の雰囲気をまとめておきたいときなどの使える良いフォントが多くあります。

10月 16th, 2009 by take | No Comments »