我很难过如何让这个工作。我正在使用 twitteroauth.php 库,并且正在从数据库查询中获取用户令牌和令牌秘密。这是代码:
while($row = mysql_fetch_array($m))
{
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];
$query = mysql_query("select url from retweets order by rand() limit 1");
$row = mysql_fetch_assoc($query);
$retweet = basename($row['url']);
$method = 'statuses/retweet/'.$retweet.'';
twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}
如果mysql有多个结果,它会循环并说:
Fatal error: Cannot redeclare random_from() (previously declared in /usr/share/nginx/www/twitteroauth/twitteroauth.php:199) in /usr/share/nginx/www/twitteroauth/twitteroauth.php on line 199
由于该$connection
变量依赖于mysql 查询$oauthToken
,$oauthTokenSecret
因此我无法将其移出循环,那么我将如何制作它以便可以在每个循环中使用它而无需重新声明?
先感谢您!
更新:这是 twitterOAuth
function twitterOAuth($method, $response, $http_code, $userName, $parameters = '') {
if($http_code == 200){
echo "retweeted successfully @".$userName."<br />";
}else{
echo "an error has occurred while retweeting @".$userName."";
echo "<br />";
print_r($response);
}
}