Biblioteca Codeigniter para la API de Twitter

Que CodeIgniter es un fabuloso framework para desarrollar en php ya lo sabemos todos y que detrás tiene una enorme comunidad de desarrolladores aumentando la funcionalidad, pues también.

codeigniter_logo

Buscando esta tarde alguna forma de mostrar tweets en una sencilla aplicación realizada con CodeIgniter, me he encontrado con “Twitter API Codeigniter Library” realizada por Elliot Haughin y me he dicho: Toca probar.

Tal y como recomienda, lo primero que hay que hacer es configurar nuestra aplicación. Hay que hacer unos pequeños cambios en el archivo config.php que se encuentra en el directorio application/config/

Ahí hay que buscar la opción uri_protocol estableciéndola a PATH_INFO y en la opción permitted_uri_chars añadir el carácter ‘?’ justo despueés de a-z

$config['uri_protocol'] = "PATH_INFO";
$config['permitted_uri_chars'] = 'a-z? 0-9~%.:_\-';

Una vez hecho esto, se pueden pegar las dos bibliotecas MY_input.php y twitter.php en application/libraries. Desde este momento, se pueden cargar en nuestro controlador y usar.

A continuación pongo el ejemplo más sencillo para hacer uso de estas bibliotecas:

$this->load->library('twitter');
$this->twitter->auth('twitter_username', 'twitter_password');
$timeline = $this->twitter->call('statuses/user_timeline');

A partir de aquí, sólo queda dejar volar la imaginación. Ejemplo de llamadas:

$this->twitter->search('search', array('q' => 'elliot'));
$this->twitter->search('trends');
$this->twitter->search('trends/current');
$this->twitter->search('trends/daily');
$this->twitter->search('trends/weekly');
$this->twitter->call('statuses/public_timeline');
$this->twitter->call('statuses/friends_timeline');
$this->twitter->call('statuses/user_timeline');
$this->twitter->call('statuses/show', array('id' => 1234));
$this->twitter->call('direct_messages');
$this->twitter->call('statuses/update', array('status' => 'If this tweet appears, oAuth is working!'));
$this->twitter->call('statuses/destroy', array('id' => 1234));
$this->twitter->call('users/show', array('id' => 'elliothaughin'));
$this->twitter->call('statuses/friends', array('id' => 'elliothaughin'));
$this->twitter->call('statuses/followers', array('id' => 'elliothaughin'));
$this->twitter->call('direct_messages');
$this->twitter->call('direct_messages/sent');
$this->twitter->call('direct_messages/new', array('user' => 'jamierumbelow', 'text' => 'This is a library test. Ignore'));
$this->twitter->call('direct_messages/destroy', array('id' => 123));
$this->twitter->call('friendships/create', array('id' => 'elliothaughin'));
$this->twitter->call('friendships/destroy', array('id' => 123));
$this->twitter->call('friendships/exists', array('user_a' => 'elliothaughin', 'user_b' => 'jamierumbelow'));
$this->twitter->call('account/verify_credentials');
$this->twitter->call('account/rate_limit_status');
$this->twitter->call('account/rate_limit_status');
$this->twitter->call('account/update_delivery_device', array('device' => 'none'));
$this->twitter->call('account/update_profile_colors', array('profile_text_color' => '666666'));
$this->twitter->call('help/test');

En esta ocasión, creo que no está de más tener a mano la API de Twitter para hacer uso de ella en cualquier momento.

Descargar la biblioteca CodeIgniter para la API de Twitter bajo licencia GNU directamente desde la página del autor.

Más información en http://www.haughin.com/code/twitter/

This entry was posted in Programación and tagged , , , . Bookmark the permalink.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *

*

Puedes usar las siguientes etiquetas y atributos HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>