0

我正在努力完善我的 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()

这是我使用的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;
4

1 回答 1

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));
于 2012-07-19T04:27:00.303 回答