有超过100条推文,但加载花费了太多时间

时间:2014-06-04 05:27:13

标签: php

我正在使用rest api 1.1 xampp服务器进行推特分析项目,所以我希望在特定主题标签上获得超过100条推文,即使我能够通过以下代码获得超过100条推文:

<?php
require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "xxx",
'oauth_access_token_secret' => "xxx",
'consumer_key' => "xxx",
'consumer_secret' => "xxx"
);
$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
$since_id=0;
$c=1;
$cc=1;
for(;$cc<=500;)
{
$getfield = '?    q='.$_POST["hash"].'&result_type=recent&count=200&lang=en&since_id='.$since_id.'';
ini_set('max_execution_time', 30);
error_reporting(0);//echo "Count: ". $cc ."";
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
foreach($string as $val)
{
      $since_id=$val['max_id_str'];

}
?>
<html>
<body>
<ul style="list-style: none;" >
<?php 
foreach($string["statuses"] as $items)
{
?>
<li>
<table border=1>
<tr>
<td rowspan=4 width=100><img src=<?php echo $items['user']['profile_image_url'];?> width=44 height=44> </td>
</tr>
<td width=600><?php echo "Count: ". $c ."";?></td>
<tr>
<td width=600><?php echo "Tweeted by: ". $items['user']['name']; ?></td>
</tr>
<tr>
<td width=600><?php echo "Location is: ". $items['user']['location']; ?></td>
</tr>
<tr>
<td  width=600><?php  echo "Tweet: ". $items['text']; ?></td>
</tr>
<tr>
<td  width=600><?php echo "Time and Date of Tweet: ".$items["created_at"]; ?></td>
</tr>
</table>
</li>
<?php $c++;
}
$cc++;
}
?>    
</ul>
</body>
</html>

但问题是这需要花费太多时间来加载一些时间或半小时的任何解决方案吗?

谢谢。

0 个答案:

没有答案