Created
May 20, 2012 07:13
-
-
Save shobotch/2757158 to your computer and use it in GitHub Desktop.
twitterAPIから特定ユーザーのツイートを大量に取得する方法とかなんとか
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//基本的にどっか別のライブラリに組み込む形がいいと思うよ。 | |
//get_friends_timeline_multiメソッドの第一引数に配列でユーザーIDを入れると配列にそいつらのツイートが全部まとめて入ってくるから複数ユーザーをふぁぼったりするときに捗るかと。 | |
//checkSourceShootingStarにツイートのsourceを送るとShootingStarか判別してくれる。stsの経験値稼ぎに貢献できるね☆ | |
require 'twitteroauth.php'; | |
class twitteroauthS{ | |
// Consumer keyの値 | |
public $consumer_key = ""; | |
// Consumer secretの値 | |
public $consumer_secret = ""; | |
// Access Tokenの値 | |
public $access_token = ""; | |
// Access Token Secretの値 | |
public $access_token_secret = ""; | |
private $login; | |
private $to; | |
public function __construct(){ | |
$this->to = new TwitterOAuth($this->consumer_key,$this->consumer_secret,$this->access_token,$this->access_token_secret); | |
$this->login = true; | |
} | |
public function getTL($count = 30) { | |
if(!$this->login)return false; | |
$req = $this->to->OAuthRequest("http://api.twitter.com/1/statuses/home_timeline.json","GET",array("count"=>$count)); | |
return json_decode($req,true); | |
} | |
public function get_friends_timeline($id,$count = 30) { | |
if(!$this->login)return false; | |
$req = $this->to->OAuthRequest("http://api.twitter.com/1/statuses/user_timeline.json","GET",array("count"=>$count,"screen_name"=>$id,"trim_user"=>1,)); | |
return json_decode($req,true); | |
} | |
public function get_friends_timeline_multi($id = array(),$count = 30) { | |
if(!$this->login)return false; | |
$return = array(); | |
foreach ($id as $user){ | |
$req = $this->to->OAuthRequest("http://api.twitter.com/1/statuses/user_timeline.json","GET",array("count"=>$count,"screen_name"=>$user,"trim_user"=>1,)); | |
foreach (json_decode($req,true) as $re) { | |
$return[] = $re; | |
} | |
} | |
return $return; | |
} | |
public function checkSourceShootingStar($source){ | |
if($source === '<a href="http://shootingstar067.com/" rel="nofollow">ShootingStar</a>'){ | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment