在脚本中使用twitter API时无法选择所有用户

时间:2011-08-22 23:41:59

标签: php mysql

我正在尝试使用他们的API为Twitter创建一个机器人。它的作用是通过“mysql select”制作所有机器人,然后记下每个机器人的状态。

由于某些原因,当我尝试选择所有机器人时它不起作用,只有在我更改以下内容时它才有效

SELECT * FROM tweeterusers

到这个

SELECT * FROM tweeterusers WHERE rid='9'

或任何其他摆脱(摆脱是我在数据库中的机器人ID)

你能告诉我我哪里出错吗?

这是完整的代码

<?
$query = mysql_query("SELECT * FROM tweeterusers") or die(mysql_error());
    while($info = mysql_fetch_array($query))
        {
            $rid=$info['rid'];
            $ConsumerKey=$info['ConsumerKey'];
            $ConsumerSecret=$info['ConsumerSecret'];
            $AccessToken=$info['AccessToken'];
            $AccessTokenSecret=$info['AccessTokenSecret'];
            $Keyword=$info['Keyword'];
            $TheTweet=$info['TheTweet'];
            $Proxy=$info['Proxy'];

            //echo $rid."<br />";
            //echo $Keyword."<br /><br />";


            define('CONSUMER_KEY', $ConsumerKey);
            define('CONSUMER_SECRET', $ConsumerSecret);
            define('ACCESS_TOKEN', $AccessToken);
            define('ACCESS_TOKEN_SECRET', $AccessTokenSecret);

            $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
            $twitter->host = "http://search.twitter.com/";
            //$search = $twitter->get('search', array('q' => $Keyword, 'rpp' => 1));


            //proxy body
            $ch = curl_init();
            curl_setopt ($ch, CURLOPT_URL, "https://api.twitter.com/1/");
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
            curl_setopt ($ch, CURLOPT_PROXY,$Proxy);
            curl_setopt ($ch, CURLOPT_PROXYUSERPWD, '397592562:d6a6cdca');
            curl_setopt ($ch, CURLOPT_TIMEOUT, 120);

            $response = curl_exec ($ch);


            //$twitter->host = $response;
            $twitter->host = "https://api.twitter.com/1/";

            if(is_int($response)) 
            {
                die("Errors: " . curl_errno($ch) . " : " . curl_error($ch));
            }
            curl_close ($ch);


                $status = "hey all";

                if(strlen($status) > 140) $status = substr($status, 0, 139);
                mysql_query("INSERT INTO tweeterstatus 
                (Status, date, time, Robot) VALUES('$status', '$date', '$time', '$rid')");

                $twitter->post('statuses/update', array('status' => $status));



                echo "
                    <tr style='background:none repeat scroll 0 0 #eae9ff;'>
                    <td align='center'>".$rid."</td>
                    <td align='center'>".$Proxy."</td>
                    <td align='center'>".$Keyword."</td>
                    <td align='center'>".$TheTweet."</td>
                    <td align='center'>".$status."</td>
                </tr>";



            sleep(1);
        }

                echo '</table>';
            ?>

1 个答案:

答案 0 :(得分:4)

您不能多次使用define

只需使用:

$twitter = new TwitterOAuth($ConsumerKey, $ConsumerSecret, $AccessToken, $AccessTokenSecret);

并摆脱define