特定のキーワードを含むツイートをした人をFollowするTwitter Botをつくってみた
初期設定
OAuthの設定はググるといろいろ出てくるので省略。
http://www.google.co.jp/search?hl=ja&q=oauth+twitter+php
Bot作成
PHPで書いています。Twitter本家のAPIドキュメントがかなり充実しているので、すんなりできた。
JSONとかPHPとか素人だったけど、特に難しくなかった。
// OAuth設定(省略)
// 発言を行うメソッドを指定
$method = "friendships/create";
// TwitterOAuthのインスタンスを生成
$twitter = new TwitterOAuth(
$consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
// 検索する
$jsonurl = "http://search.twitter.com/search.json?q=URLエンコードしたキーワード";
// ↑パスが通っているか、ブラウザに上記URLを入力して確認する。jsonをFirefox上で見るのには、<a href="http://www.moongift.jp/2009/08/jsonview/" target="_blank">JSONView</a>が便利
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
foreach ( $json_output->results as $result )
{
// echo "{$result->from_user}\n";
// パラメータを指定
$parameters = array("id" => $result->from_user);
// Twitterにフォロー要求をPOST
$response = $twitter->post($method, $parameters);
$http_info = $twitter->http_info;
$http_code = $http_info["http_code"];
if($http_code == "200" && !empty($response)) {
print "ok\n";
} else {
print "ng\n";
}
sleep(3); // 念のためスリープ。
}
CRONで定期的に実行
僕はさくらインターネットユーザーなのだが、さくらでCRON設定する方法はググると一杯出てきた。
ここが参考になった。http://d.hatena.ne.jp/Shinji_041/20090912/p2
以上、RESTは便利だー。
Mobiler
Mobiler [2010]
ポータブルアクティブスピーカー Mobiler [モバイラー]
単3乾電池駆動。iPodなどのオーディオプレイヤーに接続すれば、大音量でどこでも音楽が聴けます。
Portable Active Speaker “Mobiler”.
Powered by AA battery. You can listen music everywhere at full blast.
コスプレイヤーたみさんに装備して頂きました。
Cosplayer Tami mounts Mobiler.
photo:a.k.a.mgmkt
cosplayer:たみ [Tami]

Mobiler
Mobiler [2010]
ポータブルアクティブスピーカー Mobiler [モバイラー]
単3乾電池駆動。iPodなどのオーディオプレイヤーに接続すれば、大音量でどこでも音楽が聴けます。
Portable Active Speaker “Mobiler”.
Powered by AA battery. You can listen music everywhere at full blast.
コスプレイヤーたみさんに装備して頂きました。
Cosplayer Tami mounts Mobiler.
photo:a.k.a.mgmkt
cosplayer:たみ [Tami]
Recent entries
- jit.gl.gridshape の matrixoutput についてのメモ #max8
- jit.gl.pix で簡易モーションブラー #max8 #jitter
- jit.gl.pix で Gold Noise #max8 #jitter
- Gen で配列をつくる検討 #Max8
- Package Managerで配布されているease objectを使いやすくしてイージング #max8
- Node for Max を用いて、定形外のUDPデータを受信 #Max8 #n4m
- 平ハウス物語 – 山田尚子監督作品 非公式ファンイベント
- The Splendid Expression – GITADORA×NOSTALGIA
- ghost in my place【from DEEMO II】
- EP “Boys O’Clock”
- 7th Album “多次元宇宙論”
- LEON.jpのWEB特集「大人のいい時間」にAromが紹介されました。
- 音できらめくキャンドルライト Arom(第2世代)発売開始
- EP “Strange Story”
- 都市の呼吸【from Cytus II】