Posted By

neal_grosskopf on 09/01/09


Tagged

php twitter


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

neal_grosskopf
luman
rene-design
umang_nine


Custom Twitter Badge Using PHP


 / Published in: PHP
 

URL: http://www.nealgrosskopf.com/tech/thread.php?pid=57

Display the number of people following you on Twitter using this custom Twitter badge. The code simply returns a number so you can style it however you like.

  1. function curl($url)
  2. {
  3. $ch = curl_init($url);
  4. curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  5. curl_setopt($ch,CURLOPT_HEADER, 0);
  6. curl_setopt($ch,CURLOPT_USERAGENT,"www.YOURDOMAIN.com");
  7. curl_setopt($ch,CURLOPT_TIMEOUT,10);
  8. $data = curl_exec($ch);
  9. curl_close($ch);
  10. return $data;
  11. }
  12.  
  13. function GetTwitterFollowerCount($username)
  14. {
  15. $twitter_followers = curl("http://twitter.com/statuses/user_timeline/".$username.".xml?count=1");
  16. $xml = new SimpleXmlElement($twitter_followers, LIBXML_NOCDATA);
  17. return = $xml->status->user->followers_count;
  18. }
  19.  
  20. echo GetTwitterFollowerCount("YourTwitterName");

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: neal_grosskopf on September 4, 2009

I have an error on line 17 here. It should read: return $xml->status->user->followers_count;

Sorry for the mistake.

You need to login to post a comment.