twitterã®followingãfollowersãå¾ãã¹ã¯ãªãã
twitterããç°¡åã«followingãfollowersã®ä¸è¦§ãå¾ãæ¹æ³ã¨ãã¦ãRãããããã§ãã
iGraphでTwitterのネットワークを表してみる
igraphでTwitterのネットワークを描いてみる2
ãããã100人ã¾ã§ããåå¾ã§ããªãããåèªèº«ãRã«æ
£ãã¦ããªãã®ã§ãèªåã§ã¹ã¯ãªãããæ¸ãã¦ã¿ã¾ããã
#!/usr/bin/php <?php require_once 'Services/Twitter.php'; $user='username'; // ã¦ã¼ã¶å $pass='password'; // ãã¹ã¯ã¼ã $max_loop=10; // ããã°ã©ã ã«ãã°ããã£ãã¨ãã®ä¿éº $delay=10; // 1ãªã¯ã¨ã¹ãå¾ã®ã¹ãªã¼ãæé(ç§) class Services_Twitter2 extends Services_Twitter { public $followers_url= 'http://twitter.com/statuses/followers/%s.json?cursor=%.0f'; public $friends_url= 'http://twitter.com/statuses/friends/%s.json?cursor=%.0f'; function __construct($user,$pass) { parent::__construct($user,$pass); } function getAllFollowersFrom($user,$cursor=-1) { return $this->_getData('GET', sprintf($this->followers_url,$user,$cursor), 'getAllFollowersFrom'); } function getAllFriendsFrom($user,$cursor=-1) { return $this->_getData('GET', sprintf($this->friends_url,$user,$cursor), 'getAllFriendsFrom'); } } function usage() { fprintf(STDERR,"Usage: getwitter [-fo | -fr]\n"); exit(1); } if ($argc===2) { if ($argv[1]==='-fo') { $inquire='getAllFollowersFrom'; } else if ($argv[1]==='-fr') { $inquire='getAllFriendsFrom'; } else { usage(); } } else { usage(); } $st=&new Services_Twitter2($user,$pass); // ã¯ã©ã¤ã¢ã³ãæ å ±ãé©å½ã§ãã $st->setAppName('getwitter'); $st->setAppVersion('0.0.1'); while (($target=fgets(STDIN))!==FALSE) { $results=array(); $target=rtrim($target); $people_json=$st->$inquire($target); $people=json_decode($people_json); for ($i=0;$i<$max_loop && !empty($people);$i++) { if (count($people->{'users'})===0) { sleep($delay); break; } foreach ($people->{'users'} as $person) { /* * 100人ãè¶ ãã¦åå¾ããå ´åãä½æ ããã¾ã«éè¤ãã */ if (!isset($results[$person->{'screen_name'}])) { fprintf(STDERR,$target."\t".$person->{'screen_name'}."\n"); $results[$person->{'screen_name'}]=1; } } if ($people->{'next_cursor'}===0) { // ãã次ã¯ãªã sleep($delay); break; } sleep($delay); $people_json=$st->$inquire($target,$people->{'next_cursor'}); $people=json_decode($people_json); } } ?>
Services_Twitterã使ã£ã¦ããã®ã§ãäºåã«ã¤ã³ã¹ãã¼ã«ãã¦ããã¦ãã ããã
ãã®ã¹ã¯ãªããã¯æ¨æºå
¥åããä¸è¦§ãå¾ããã¦ã¼ã¶åãå
¥åãããæ¨æºã¨ã©ã¼åºåãã«çµæãåºåãã¾ããæ¨æºåºåã«ã¯ããããããªãã¡ãã»ã¼ã¸ãServices_Twitterããåºãã®ã§åºåãåãã¾ããã
followingã®ä¸è¦§ãåºåãããå ´åã¯ã-frããªãã·ã§ã³ãä»ããfollowersã®ä¸è¦§ãåºåãããå ´åã¯ã-foããªãã·ã§ã³ãä»ãã¾ãã
çµæã®å½¢å¼ã¯æ¬¡ã®éãã§ãã
ã¦ã¼ã¶å1\t人1 ã¦ã¼ã¶å1\t人2 ã¦ã¼ã¶å1\t人3 . . .
人1ã2ã3ã¨ããã®ã¯followingãã¾ãã¯followersä¸è¦§ã«ååããã人ã®ãã¨ã§ãã
ãªããåããåã«$userã$passã$max_loopã$delayãè¨å®ãã¦ããã¦ãã ããã
使ç¨ä¾ãæãã¦ããã¾ãã
å
¥åç¨ã®ãã¡ã¤ã«
æ¨æºå
¥åããã¦ã¼ã¶åãå
¥åã§ããã®ã§ããã¡ã¤ã«ã«æ¸ãã¦ããã¨ä¾¿å©ã§ãã
ã¦ã¼ã¶å1 ã¦ã¼ã¶å2 ã¦ã¼ã¶å3 . . .
followingã®ä¸è¦§ãåå¾
bashã®å ´å
getwitter.php -fr < å ¥åãã¡ã¤ã« 1> /dev/null 2> åºåãã¡ã¤ã«
followersã®ä¸è¦§ãåå¾
bashã®å ´å
getwitter.php -fo < å ¥åãã¡ã¤ã« 1> /dev/null 2> åºåãã¡ã¤ã«
ã¹ã¯ãªããèªä½ã¯åç´ã ã¨æãã®ã§ãæ¯éç¨éã«å¿ãã¦æ¹é ãã¦ãã ãã!