从数据库中的url检索Twitter数据

时间:2016-08-07 15:16:02

标签: php database twitter phpmyadmin

我正在尝试使用twitter api exchange从twitter api中检索数据。我有一个关于phpmyadmin的数据库,有很多twitter链接,我需要为每个帐户获取followers_count。代码似乎运行,但它真的很慢,并且十分之一的工作。这是我的代码:

<?php 


require_once('TwitterAPIExchange.php'); 


$settings = array(
    'oauth_access_token' => "aaaaaaaaaa-bbbbbbbb",
    'oauth_access_token_secret' =>"cccccccccc",
    'consumer_key' => "dddddddddddd",
    'consumer_secret' => "eeeeeeeeee"
);


$bdd = new PDO('mysql:host=localhost;dbname=rise', 'root', 'mali');
$reponse = $bdd->query('SELECT * FROM usa WHERE administrative_area_level_1 = "NY"');

while ($donnees = $reponse->fetch())

{
    $id_twitter = str_replace('https://twitter.com/', '',$donnees['twitter']);
    $ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; 
    $getfield = '?screen_name=' . $id_twitter;

    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $follow_count=$twitter->setGetfield($getfield)
        ->buildOauth($ta_url, $requestMethod)
        ->performRequest();
    $data = json_decode($follow_count, true);

    $followers_count=$data[0]['user']['followers_count'];
    $screen_name = $data[0]['user']['screen_name'];

    echo $screen_name  . " : " . $followers_count . '<br>' ; 
}
?>

我宁愿说清楚,我是编码的新手,请不要太技术化。 谢谢你的帮助:))

0 个答案:

没有答案