
Welcome to the fancy-new version of the Twitter API CodeIgniter Library.
How do you like this for simplicity?
This page is currently being updated for oAuth functions
Important!
To make this work, you will need to make a couple of crucial changes to your application/config/config.php
Open up your application/config/config.php file. Scroll down to the uri_protocol option and change it to ‘PATH_INFO’. Then go to the uri_allowed_chars setting and place a question mark ‘?’ after ‘a-z’. This allows you to put question marks in the URL. That’s it!
Once you’ve done this, you can drop the two libraries (MY_Input.php and Twitter.php) into you application/libraries/ directory.
Bundled with the release is some sample controller code. This code uses sessions to store the all-important access_token and access_token_secret. But, you could use a database for this.
Using basic authentication
$this->load->library('twitter'); $this->twitter->auth('username', 'password'); $timeline = $this->twitter->call('statuses', 'friends_timeline');
Using oauth authentication
To use auth, you will need to register an oAuth Client here.
Make sure you point the ‘callback url’ to the url of the controller code provided in the library.
Now you can use oauth to your heart’s content, just use the example controller code.
This library provides an interface to Twitter’s beautiful API. What’s more – it tries to stick as close to the original specification as possible. So, all you need is the ‘Twitter Api Documentation‘, and you should be good to go! This library also handles Twitter’s search API (see examples below).
Here’s some examples of more ‘complex’ (yeah right!) calls:
Updating your status:
$this->twitter->call('statuses', 'update', array('status' => 'Elliot Rocks!'));
Get the third page of someone else’s followers:
$this->twitter->call('users', 'followers', array('id' => 'dallard', 'page' => 3));
Use the search method
$this->twitter->search('search', array('q' => 'haughin'));
Trending topics
$this->twitter->search('trends');
Full list of calls available
$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');
REQUIREMENTS:
- php5
- curl
- json_decode
TODO:
- Profile Image Uploads
- Background Image Uploads
- Curl Cookie based sessions? – Maybe
Download Twitter API CodeIgniter Library
License: GNU GENERAL PUBLIC LICENSE – Version 2
Version: 3.1
Update: Version 3.1 (2009-05-01): Fixed bug when calling method with ‘/’ in name.
Update: Version 3.0 (2009-05-01): Added oAuth. Complete rewrite, as noted in this post.
Update: Version 2.2 (2009-03-07): Fixed user_timeline bug found by sophistry




@Odin: Sorry, it’s been a while ago and I can’t remember. Hope you figured it out yourself though!
Hi All,
I faced two problems and here are the solutions:
1. “header(’Location: ‘.$url);” should be followed immediatelly by a ‘die();’ statement otherwise the function may return TRUE before the desired redirection. May be a problem on the faster servers only.
2. I suspect that due to the asynchronous mode of the EpiTwitter library I could not make the oauth work until I forced an access to one of the variables it returned. Specifically, here it is:
$info = $this->oauth->getAccessToken();
strlen($info->oauth_token);//oauth_token) && !empty($info->oauth_token_secret) )…
Again, the server may be too fast and the php would test $info->oauth_token before CURL’s return so it would have no value. It seems that a strlen() forces the script to wait exactly as it needs for that variable to get a value.
Hi
i m using this code for twitter and it always redirect back to wrong url please help me if you can
Thanks in advance
Hi Alex,
I don’t understand this part, $info = $this->oauth->getAccessToken();
strlen($info->oauth_token);//oauth_token) && !empty($info->oauth_token_secret) ). What are you replaceing?
Thanks,
Víctor
In bacic mode there seams the be an issue around line 141, when authentication credentials are passed you should continue and not return null
if ( $auth === TRUE && ( $this->_conn->authed() || $this->oauth === NULL) ) {
} else {
// method requires auth, and we have not authed yet
return NULL;
}
Also
this->twitter->call(’statuses’, ‘update’, array(’status’ => ‘Elliot Rocks!’));
from your example is deperecated it should be
this->twitter->call(’statuses/update’, array(’status’ => ‘Elliot Rocks!’));
hey i can connected to twiter then i got PIN how to update my twitter? i can’t update it.. thx for help
anyone having trouble getting this going? I get a twitter authorization URL without oauth_token key
Hello guys
Have you solved the post tweet issue ?
I can’t post my tweets…
Here is my simple test:
$this->load->library(’twitter’);
$this->twitter->auth(’user’,'pass’);
$out = $this->twitter->call(’statuses/update’, array(’status’ => ‘trying the twitter lib’));
var_dump($out);
$out gives me NULL….
what about you guys ?
Thanks!
[...] CodeIgniter Twitter Lib [...]
Installing now on a fresh CI install. If this works as promised, you are a bad motha!
Hi there,
I found that the basic auth wasnt working, so I changed the following line (146 i think):
if ( $auth === TRUE && ( $this->_conn->authed() || $this->oauth === NULL) )
to
if ( $auth === TRUE && ( !$this->_conn->authed() && $this->oauth === NULL) )
Im not sure if its ideal in terms fixing the problem, but it stopped it from prematurely returning NULL.
Hope it helps.
First of all, thanks a lot for the awesome library! I so needed it!
I’ve it up and running and it’s amazing!
I wonder…how can I get the username once I’ve logged in via oAuth? What should I call to get it?
Thanks again.
Alberto
[...] API CodeIgniter Library oleh Eliot Haughin. [...]
thanks for the wonderful libraries haughin!
correct me if i’m wrong but you don’t actually need the MY_Input library file
to allow_get_array since by changing one variable in the config.php file u can already do that:
$config['enable_query_strings'] = TRUE;
having a bit of an issue with the OAuth, in the oauth function of the twitter library, if I call this on line 91:
echo($url);
exit;
all I get in return is
http://twitter.com/oauth/authorize?oauth_token=
There’s no token given, any ideas why?
Hey Elliot, awesome implementation. I’ve got most of it working but have a question about lists. I thought I’d try my not-very-good-programmer attempt at adding lists to the mix by adding the line:
‘tes735/lists/darkmatter/statuses’ => array(’http’ => ‘get’, ‘auth’ => FALSE)
in the array as a test, but I only get a zero length json in the lists[] as a return from twitter. Any ideas why? I read somewhere that the pagination might be muxing up the json_decode.
Do you think you’ll be adding Lists functionality soon?