2012-07-19 72 views
0

我試圖完善我的Twitter機器人,並且我一直在困擾着我一段時間。基本上,每當我試圖執行此代碼:Twitter獲取功能

<? 

$consumerKey = '------'; 
$consumerSecret = '------'; 
$oAuthToken  = '------'; 
$oAuthSecret  = '------'; 

include "OAuth.php"; 
include "twitteroauth.php"; 

$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret); 

    echo "Your message has not been sent to Twitter."; 
$twitter->host = "http://search.twitter.com/"; 
$search = $twitter -> get('search', array('q' => 'pool -table -TowlieBot -#pool :)', 'rpp' => 15)); 

$twitter->host = "https://api.twitter.com/1/"; 
foreach($search->results as $tweet) { 
    $tweet->post('statuses/update',array('status' => '@'.$tweet->from_user.': Don\'t forget to bring a towel.')); 
} 
?> 

我得到致命錯誤:第16行調用未定義的方法stdClass的::得到()。

這裏的get函數我用:

function get($url, $parameters = array()) { 
    $response = $this->oAuthRequest($url, 'GET', $parameters); 
    if ($this->format === 'json' && $this->decode_json) { 
     return json_decode($response); 
    } 
    return $response; 
+0

我希望那些不是你在那裏的真正的鑰匙! – 2012-07-19 04:28:51

+0

哦shieeeeee- 感謝您指出 – David 2012-07-20 00:45:19

+0

哈哈,不用擔心隊友,到目前爲止只有16個視圖:-D – 2012-07-20 00:52:05

回答

0

您正在使用您的TwitterOAuth對象兩個不同的變量 - $tweet$twitter。儘量挑選一個:

$twitter = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret); 

echo "Your message has not been sent to Twitter."; 
$twitter->host = "http://search.twitter.com/"; 
$search = $twitter -> get('search', array('q' => 'pool -table -TowlieBot -#pool :)', 'rpp' => 15));