I am trying to create a bot for Twitter using their API. What it does, is take all the robots I made by "mysql select" and then write down a status for each one.
For some reason it doesn't work when I am trying to select all the robots, it only works if I am changing the following
SELECT * FROM tweeterusers
to this
SELECT * FROM tweeterusers WHERE rid='9'
or any other rid (where rid is the robot id I have in the database)
Can you please show me where I am going wrong?
This is the full code
<?
$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>';
?>
You can not use define
more than once.
Just use:
$twitter = new TwitterOAuth($ConsumerKey, $ConsumerSecret, $AccessToken, $AccessTokenSecret);
and get rid of the define
精彩评论