Guest User

Untitled

a guest
Jun 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. session_save_path("/tmp");
  2. session_start();
  3. ini_set('display_errors', 1);
  4. require_once('TwitterAPIExchange.php');
  5.  
  6. //setting the api connection
  7.  
  8. $settings = array(
  9. 'oauth_access_token' => "****",
  10. 'oauth_access_token_secret' => "****",
  11. 'consumer_key' => "****",
  12. 'consumer_secret' => "****"
  13. );
  14.  
  15. $url ="https://api.twitter.com/1.1/search/tweets.json";
  16. $requestMethod = 'GET';
  17.  
  18.  
  19. //displaying the search results
  20.  
  21. $twitter = new TwitterAPIExchange($settings);
  22.  
  23. $_SESSION['key'] ='';
  24. if(isset($_GET['results']))
  25. {
  26. $r_count = $_GET['results'];
  27. }
  28. if(isset($_GET['keyword']))
  29. {
  30. 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>");
  31.  
  32. $result = '?q=%23'.$_GET['keyword'].'&result_type=recent&count='.$r_count.'';
  33. $key = $_GET['keyword'];
  34. $result = preg_replace("/b([a-z]*${key}[a-z]*)b/i","<b>$1</b>",$result);
  35. $string = $twitter ->setGetfield($result)
  36. ->buildOauth($url, $requestMethod);
  37. ->performRequest();
  38. $response = json_decode($string);
  39.  
  40. echo "<table border='1'>";
  41. echo "<th>Display Name</th>";
  42. echo "<th>handle</th>";
  43. echo "<th>Tweet</th>";
  44. echo "<th>Location</th>";
  45. foreach($response->statuses as $tweet)
  46. {
  47. echo "<tr>";
  48. //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>";
  49. 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>';
  50. echo "</tr>";
  51. }
  52. echo "</table>";
  53. }
Add Comment
Please, Sign In to add comment