Thursday, September 24, 2009

Twitter profile pull

One of my friends wanted to pull profile data from twitter and asked for some basic code. I am posting the mockup as it might prove interesting to someone else.


<?PHP
   $output = $xml_content = '';
   $tw_name = 'jeremiahstover';
   $xml_content = simplexml_load_file("http://twitter.com/users/show.xml?screen_name=$tw_name");
   $xml_content2 = simplexml_load_file("http://twitter.com/statuses/friends/$tw_name.xml");

$output .= "
   <html>
      <head>
         <style>
            .tw_profile{
               width:200px;
               border:1px solid black;
               overflow:hidden;
            }            
         </style>
      </head>
      <body>
         <div class='tw_profile'>
            <a href='". $xml_content->url ."'>
               <div class='avatar'>
                  <img src='".$xml_content->profile_image_url."'>
               </div>
               <div class='avatar_title'>".$xml_content->name."</div>
            </a>
            <div class='description'>".
               $xml_content->description   ."
            </div>
            <div class='friends'>
               <strong>Friends:</strong><br>
               <i>  ";

               foreach($xml_content2 as $friend){
                  $name = $friend->name;
                  $url = $friend->url;
                  $output .= "<a href='$url'>$name</a><br>";
               }

             $output .= "
             </i>
          </div>
       </div>
    </body>
</html>
";

echo $output;

?>