1

i have a small app on which users can enter a specific keyword on a searchbox and when they click on 'search', a table containing tweets based on the keywords is displayed. what i want to further achieve with this exercise, is to be able to receive notifications based on this keyword every time someone tweets about about without me having to search again.someone please help.

This is how my search code looks like so far:

 session_save_path("/tmp");
 session_start();
 ini_set('display_errors', 1);
 require_once('TwitterAPIExchange.php');

//setting the api connection

$settings = array(
'oauth_access_token' => "****",
'oauth_access_token_secret' => "****",
'consumer_key' => "****",
'consumer_secret' => "****"
);

$url ="https://api.twitter.com/1.1/search/tweets.json";
 $requestMethod = 'GET';


//displaying the search results

$twitter = new TwitterAPIExchange($settings);

$_SESSION['key'] ='';
if(isset($_GET['results']))
{
    $r_count = $_GET['results'];
}
if(isset($_GET['keyword']))
{
    print_r("<p style='padding-left:1em;color:#FFC20E;font-size:20px'>Search Results for Keyword: <span style='font-weight: bold'>".$_GET['keyword']."</span></p><br>");

$result = '?q=%23'.$_GET['keyword'].'&result_type=recent&count='.$r_count.'';
$key = $_GET['keyword'];
$result = preg_replace("/\b([a-z]*${key}[a-z]*)\b/i","<b>$1</b>",$result);
$string = $twitter ->setGetfield($result)
            ->buildOauth($url, $requestMethod);
           ->performRequest();  
$response = json_decode($string);

echo "<table border='1'>";
echo "<th>Display Name</th>";
echo "<th>handle</th>";
echo "<th>Tweet</th>";
echo "<th>Location</th>";
foreach($response->statuses as $tweet)
{
    echo "<tr>";
    //echo "<td> {$tweet->user->name} </td><td><img src={$tweet->user->profile_image_url}/>{$tweet->user->screen_name} </td><td> {$tweet->text}</td><td> {$tweet->user->location}</td>";
    echo '<td>'.$tweet->user->name.'</td><td><img  height="35" style="width:35px;display:inline-block" src="'.$tweet->user->profile_image_url.'"/><a style ="color: #0075c9" target="_blank" href="https://twitter.com/'.$tweet->user->screen_name.'">@'.$tweet->user->screen_name.'</a></td><td>'.$tweet->text.'</td><td>'.$tweet->user->location.'</td>';
    echo "</tr>";
}
echo "</table>";
}
  • I think you want to take a look at https://developer.twitter.com/en/docs/tweets/filter-realtime/overview –  Jun 21 '18 at 00:58

0 Answers0