Tags

, , , ,


I know this one is old thing and helps is available but sometime we need to fetch twitter feeds Retwittet, Mentions, to our websites. Now i used json request and format the texts and print.

 function twi_fid(){
  
  ## NUMBER OF TWITTET 
  $size = 5;
  
  ## FETCH THE TWITTER TWITTET
  $twittet = file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=bdsarwar&count=$size&include_rts=t&include_entities=t");
  
  
  $data = json_decode($twittet);
  $o_text = "";
  foreach($data as $t)
  {
      $o_text = $t->text;
      
      ## MAKING URLS ENABLE TO TEXT
      $entities = $t->entities;
      
      $i = 0;
      foreach($entities->urls as $url)
      {
          $indicate = $url->indices;

          $replace[$i] = $url->url;
          $string[$i] = "<a target='_blank' href='".$url->url."'>".$url->url."</a>";

          
          $i++;
      }
      
      ## MAKING MENTIONS 
      foreach($entities->user_mentions as $mention)
      {
          $indicate = $mention->indices;
          
          $string[$i] = "<a target='_blank' href='http://www.twitter.com/".$mention->screen_name."'>".$mention->screen_name."</a>";
          $replace[$i] = $mention->screen_name;
          
          $i++;
      }
     
      for($i = 0; $i < count($string); $i++)
      {
          
          $pattarn = $replace[$i];
          $o_text = str_replace($pattarn, $string[$i], $o_text);
     
      }
      
    echo $o_text;
    echo "<br />";
    echo date("d/m/Y, H:m a", strtotime($t->created_at));
    echo "<br/> ___ <br />";

      
  }
  }
  twi_fid();

For detail parameter please visit: http://apiwiki.twitter.com/w/page/22554679/Twitter-API-Documentation
and for user timeline json visit http://dev.twitter.com/doc/get/statuses/user_timeline

Done !!

Advertisement