[Tweets]

20/04/2018 6:16pm
DART: Noise injection for robust imitation learning via @Robohub [LINK]
18/04/2018 12:44am
RT @UomRobotics: Check out Festo's New Bionic Robots Include Rolling Spider, Flying Fox [LINK] @Festo are real world leade…
17/04/2018 8:47pm
A new exciting #postdoc position in #swarm #robotics at @unisouthampton [LINK]
12/04/2018 12:24am
RT @wjscheirer: Pre-print of the long awaited position paper: "The Limits and Potentials of Deep Learning for Robotics." Provocative stuff…

[How I Added My Twitter Feed]

Added on 18/08/2012
Tags: web


Following my decision to leave Facebook, I have decided to start using Twitter more as a means of exchanging information with my friends. Adding a Twitter feed is pretty easy as Twitter does not require you to authenticate so you can just ask for N latest tweets using an ordinary GET request.

I modified original PHP code posted on Stack Overflow to create a single function that gets the feed and converts it to tweet objects containing createdDate and message fields. Also, I added my own algorithm that automatically creates html links when it finds phrases starting with http:// . Finally, I used a method by kn00tcn to convert Twitter date to PHP date object and back to a string with my own formatting.

The PHP function is as follows:

/**
* Get tweets
*/

protected function getTweets() {
   //-- curl request    
   $url = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=elendurwen&count=5&trim_user=true";
   $ch = curl_init();    $timeout = 5;
   curl_setopt($ch,CURLOPT_URL,$url);
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
   curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   $json = curl_exec($ch);
   curl_close($ch);

   //-- parse data:
   $tweets = array();
   if ($json != false) {
      $obj = json_decode($json);

      foreach($obj as $var => $value) {
         //-- convert the date and add 4 hours to it. For some reason the conversion makes the date 4 hours less than it should be.

         $tweet['createdDate'] = date("d/m/Y g:ia",strtotime($obj[$var]->created_at) + 4*60*60);
         //-- get the message text
         $tweet['message'] = $obj[$var]->text;
         //-- add links automatically
         $tweet['message'] = preg_replace('/(?<!a href=\")(?<!src=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i', '\\0', $tweet['message']);
         //-- replace twitter name tags with links
         $tweet['message'] = preg_replace('/(?<=^|\s)@([a-z0-9_]+)/i','@$1', $tweet['message']);
         //-- replace twitter hash tags with links
         $tweet['message'] = preg_replace('/(?<=^|\s)#([a-z0-9_]+)/i','#$1', $tweet['message']);
         $tweets[] = $tweet;
      }
   }
   return $tweets;
}



{Please enable JavaScript in order to post comments}

[You might also be intested in...]

Why I Left Facebook
I decided to delete almost all my activity and all my photos from Facebook when they announced that Timeline would become compulsory. While I really think that Timeline is a bad idea as it lets your history be browsed in a very easy manner, this was not the only reason I left...
Kinect-Controlled News Feed
During my work for Edelman Digital in 2011, I took part on a C++ project to create a program that could display user’s Facebook and Twitter feeds and was controlled by hand gestures captured by a Kinect device connected to a PC.
V-REP, Gazebo or ARGoS? A robot simulators comparison
Let’s have a look at three commonly used open-source simulators for robotics: V-REP, Gazebo and ARGoS, to find out which one suits your project the best.
Designing Effective Roadmaps for Robotics Innovation
Automated factories, autonomous delivery drones, self-driving cars: these and similar technologies will soon touch every aspect of our lives. An engaging discussion about how these technologies are regulated and innovated took place at the IROS 2017 conference.
The Information-Cost-Reward framework for understanding robot swarm foraging
The Information-Cost-Reward (ICR) framework relates the way in which robots obtain and share information about where work needs to be done to the swarm’s ability to exploit that information in order to perform work efficiently in the context of a particular task and environment.
Behaviour-Data Relations Modelling Language For Multi-Robot Control Algorithms
Behaviour-Data Relations Modeling Language (BDRML) explicitely represents behaviours and data that robots utilise, as well as relationships between them. This allows BDRML to express control algorithms where robots cooperate and share information with each other while interacting with the environment.