0

我很难过如何让这个工作。我正在使用 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);
        }
}
4

1 回答 1

0

它需要看起来像这样......

while($row = mysql_fetch_array($m))
{   

$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];

$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);

$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);
}

您在声明要传递给它的变量之前声明它......

于 2013-06-23T20:30:12.997 回答