I am working on the twitter hashtag search API project using twitter Oauth by Abraham Williams.
I am getting the hashtag tweets but i have one problem.
For example, there are only 2 tweets that have been entered into the hashtag, but my function gets latest 100 tweets and keep updating the database(i have managed duplicate items).
How to use since_id and max_id for eliminating the way of getting remaining tweets. My code
//Hashtag Specification
$search = "#KejriwalFirSe";
$notweets = 100;
//Hastag Connection Starts
$search = str_replace("#", "%23", $search);
$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json? q=".$search."&count=".$notweets.);
//Parsing the twitter Data
$string1 =json_encode($tweets);
$string = json_decode($string1, true);
echo count($tweets);
foreach($string['statuses'] as $tweet)
{
$text = trim($tweet['text']);
$id =$tweet['id'];
$user_name=$tweet['user']['screen_name'];
$profile_image=$tweet['user']['profile_image_url'];
$user_id=$tweet['user']['id'];
//TimeZone for india
$date = new DateTime($tweet['created_at']);
$date->setTimezone(new DateTimeZone('Asia/Kolkata'));
$formatted_date = $date->format('h:i, M d');
echo "<br>";
echo "<img src='".$profile_image. "'/>".' '. $id .'<br/> '.$user_name.'<br/> ' . $text.' <br/>'.$formatted_date ."</br><br/>";
//Conditional Statements for inserting and updating
$select_query=$con->query("SELECT Twitter_status FROM Twitter_status WHERE Tweet_ID = '$user_id'") or die (mysqli_error());
$result = $select_query->num_rows;
if(!$result){
//Inserting the data in to the table
$ins_sql="INSERT INTO Twitter_status (Tweet_ID,Twitter_User,Twitter_status,Twitter_Profile,TotalTweets_User) VALUES ('$user_id','$user_name','$text','$profile_image',1)";
$con->query($ins_sql);
}
else
{
$con->query("UPDATE Twitter_status SET Twitter_status='updated12',TotalTweets_User=TotalTweets_User+1 WHERE Tweet_ID='$user_id'");
}
}