EurenikZ

PHP: Neuesten Tweet von einem User ausgeben

Apr 21st, 2020
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1. <?php
  2. require_once('twitter-api-php/TwitterAPIExchange.php'); // https://github.com/J7mbo/twitter-api-php
  3.  
  4. $settings = array(
  5.     'consumer_key' => 'API_KEY',
  6.     'consumer_secret' => 'API_SECRET_KEY',
  7.     'oauth_access_token' => '',
  8.     'oauth_access_token_secret' => ''
  9. );
  10.  
  11. $screen_name = 'EurenikZ'; // Twitter Account Name
  12.  
  13. $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
  14. $getfield = '?screen_name='.$screen_name;
  15. $requestMethod = 'GET';
  16.  
  17. $twitter = new TwitterAPIExchange($settings);
  18. $user_timeline = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
  19.  
  20. $i = -1;
  21. $safety = 0;
  22. do {
  23.     $i++;
  24.     $safety++;
  25.     $try = json_decode($user_timeline)[$i]->in_reply_to_status_id;
  26. } while (($try != NULL) && $safety < 20);
  27.  
  28. $latestTweet = substr(json_decode($user_timeline)[$i]->text, 0, strpos(json_decode($user_timeline)[$i]->text, 'https://t.co/'));
  29. $created_at = json_decode($user_timeline)[$i]->created_at;
  30. $id = json_decode($user_timeline)[$i]->id;
  31. $url = 'https://twitter.com/'.$screen_name.'/status/'.$id;
  32.  
  33. // Datum auswerten
  34. $monat = substr($created_at, 4, 3);
  35. if($monat == 'Jan') $monat = '01';
  36. if($monat == 'Feb') $monat = '02';
  37. if($monat == 'Mar') $monat = '03';
  38. if($monat == 'Apr') $monat = '04';
  39. if($monat == 'May') $monat = '05';
  40. if($monat == 'Jun') $monat = '06';
  41. if($monat == 'Jul') $monat = '07';
  42. if($monat == 'Aug') $monat = '08';
  43. if($monat == 'Sep') $monat = '09';
  44. if($monat == 'Okt') $monat = '10';
  45. if($monat == 'Nov') $monat = '11';
  46. if($monat == 'Dec') $monat = '12';
  47. $tag = substr($created_at , 8, 2);
  48. $stunde = substr($created_at , 11, 2);
  49. $minute = substr($created_at , 14, 2);
  50. $jahr = substr($created_at , 26, 4);
  51.  
  52. $created_at = date_create($tag.'.'.$monat.'.'.$jahr.' '.$stunde.':'.$minute);
  53. date_add($created_at, date_interval_create_from_date_string('2 hours'));
  54. $datum = date_format($created_at, 'd.m. H:i');
  55.  
  56. echo $latestTweet.'<br><br>Vom '.$datum.' Uhr.<br><br>'.$url;
  57. ?>
Add Comment
Please, Sign In to add comment