Home > PHP | Twitter > Google Trends のキーワードを投稿する Twitter bot

Google Trends のキーワードを投稿する Twitter bot

Google で検索数が急上昇しているキーワードを、Twitter に投稿する bot を作りました。

Twitter / google_trends

元になるページはこちら。
急上昇ワード

実際には、こちらの XML 形式で返してくれる API から取得しています。
http://www.google.com/m/services/trends/get

今のところ 1 時間毎 cron で取得し、トップ 10 を配信しています。

ソース


<?php
require_once 'HTTP/Client.php';

// パラメータ
$username = 'google_trends';
$password = '**********';
$auth = array(
  'Authorization' => 'Basic '.base64_encode($username.':'.$password)
);
$link_url = 'http://tinyurl.com/6r7zux';

// Google Trends の XML からキーワードを抽出
$items = array();
$xml = simplexml_load_file('http://www.google.com/m/services/trends/get');
if($xml) {
  for($i = 0; $i < 10; $i++) {
    $query = $xml->item[$i]->query;
    if($query) {
      $items[] = mb_convert_encoding($query, 'UTF-8', 'auto');
    }
  }
} else {
 return;
}
$status = $link_url.' '.implode(', ', $items);

// Twitter に post
$client =& new HTTP_Client(null, $auth);
$http_status = $client->post("http://twitter.com/statuses/update.xml", array('status' => $status));
?>

やってることはいたって単純。SimpleXML を使って Google Trends の XML を取得して、Twitter に BASIC 認証して発言するだけです。

関連リンク
GoogleのHotなキーワードを知る - ぼくはまちちゃん!(Hatena)
2008-05-25 - 思いつき Lab.

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://www.sukechan.net/archives/62/trackback/
Listed below are links to weblogs that reference
Google Trends のキーワードを投稿する Twitter bot from sukechan.net

Home > PHP | Twitter > Google Trends のキーワードを投稿する Twitter bot

Search
Feeds
Meta

Return to page top