jmlapam

Untitled

Jun 18th, 2013
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $consumer_key = 'xxxx';
  4. $consumer_secret = 'xxxx';
  5. $oauth_token = 'xxxx';
  6. $oauth_token_secret = 'xxxx';
  7.  
  8. require_once('class/twitteroauth.php');
  9. $connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
  10. $connection->host = "https://api.twitter.com/1.1/";
  11. $query = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=tweetpressfr&count=3'; //Your Twitter API query
  12. $content = $connection->get($query);
  13. $code = $connection->http_code;
  14. //Tweet Markup
  15. if(!empty($content)){ foreach($content as $tweet){
  16. echo utf8_decode(parseTweet($tweet->text));
  17. }}
  18.  
  19. function parseTweet($text) {
  20. $text = preg_replace('#http://[a-z0-9._/-]+#i', '<a target="_blank" href="$0">$0</a>', $text); //Link
  21. $text = preg_replace('#@([a-z0-9_]+)#i', '@<a target="_blank" href="http://twitter.com/$1">$1</a>', $text); //usernames
  22. $text = preg_replace('# \#([a-z0-9_-]+)#i', ' #<a target="_blank" href="http://search.twitter.com/search?q=%23$1">$1</a>', $text); //Hashtags
  23. $text = preg_replace('#https://[a-z0-9._/-]+#i', '<a target="_blank" href="$0">$0</a>', $text); //Links
  24. return $text;
  25. }
  26. ?>
RAW Paste Data