Hi,
I was surprised when my program is not running. after browsing I found that REST API v.1 been destroyed. previously, i use the API v.1 with ATOM response.
Are there any friends here who can help me examine what should I change about my line of code.
Any help will be greatly appreciated.
Thanks in advance.
//index.php
<?php
require('twitter.class.php');
$twitter = new twitter_class();
echo $twitter->getTweets('arsenal', 10);
?>
//twitter.class.php
<?php
class twitter_class
{
function twitter_class()
{
$this->realNamePattern = '/\((.*?)\)/';
$this->searchURL = 'http://search.twitter.com/search.atom?lang=en&q=';
$this->intervalNames = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
$this->intervalSeconds = array( 1, 60, 3600, 86400, 604800, 2630880, 31570560);
$this->badWords = array('somebadword', 'anotherbadword');
}
function getTweets($q, $limit=15)
{
$output = '';
$ch= curl_init($this->searchURL . urlencode($q));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$response = curl_exec($ch);
if ($response !== FALSE)
{
$xml = simplexml_load_string($response);
$output = '';
$tweets = 0;
for($i=0; $ientry); $i++)
{
$crtEntry = $xml->entry[$i];
$account = $crtEntry->author->uri;
$image = $crtEntry->link[1]->attributes()->href;
$tweet = $crtEntry->content;
$foundBadWord = false;
foreach ($this->badWords as $badWord)
{
if(stristr($tweet, $badWord) !== FALSE)
{
$foundBadWord = true;
break;
}
}
$tweet = str_replace('<a href=', '
published);
if ($secondsPassed>0)
{
for($j = count($this->intervalSeconds)-1; ($j >= 0); $j--)
{
$crtIntervalName = $this->intervalNames[$j];
$crtInterval = $this->intervalSeconds[$j];
if ($secondsPassed >= $crtInterval)
{
$value = floor($secondsPassed / $crtInterval);
if ($value > 1)
$crtIntervalName .= 's';
$time = $value . ' ' . $crtIntervalName . ' ago';
break;
}
}
}
$output .= '
';
}
}
else
$output = '' . curl_error($ch) . '
';
curl_close($ch);
return $output;
}
}
?>