2012-07-19 75 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));