twitterのフォロワーを取得する

2009年12月23日(更新日2009年12月24日)
By 石間

twitterのフォロワーを取得するスクリプトを書いてみた。
$followersに指定したアカウントのフォロワーが格納される。PHPのSnoopy.classhtmlSQLでtwitterのXMLファイルからscreen_nameタグのtextを取得するという方法で実現した。htmlSQLはXMLのようにタグで作られている時に絶大な効果を発揮することがわかります。

Snoopy.classやhtmlSQLは自分の環境に合わせて取り込むようにパスを変更すること

require_once("./Snoopy.class.php");
require_once("./htmlsql.class.php");

	$wsql = new htmlsql();
	$username = "ishimaken";   // フォロワーを取得したいTwitter のアカウント

$obj = new twitter;
$followers = $obj->GetFollower($username);
	print_r ($followers);

class twitter{
	function GetFollower($username){
    	$wsql = new htmlsql();
	    //connect to a URL  get followers
	    	if (!$wsql->connect('url', 'http://twitter.com/statuses/followers.xml?screen_name='.$username)){
    	    	exit;
	    	}
    		if (!$wsql->query('SELECT text FROM screen_name')){
        		exit;
	    	}

    		foreach($wsql->fetch_array() as $row){
    				$args[]=$row["text"];
			}
			return $args;
	}
}

人気度: 5%


こんな記事も読まれています

WP to Twitterを入れてみた - 2009年12月4日
「みがわったー」で勝手にtweet! - 2009年12月21日
htmlSQLでHTMLから必要な情報を取得 - 2009年12月17日
コンビニ初 ファミマのtwitterアカウント ファミマなう - 2009年12月4日
インテルのアシタロボ - 2009年11月25日

Tags: , , ,

Comments are closed.