Search code examples
apicodeigniterresttwitterrest-client

Using Rest Codeigniter library with Twitter API


I have setup the Rest library by Phil Sturgeon to connect to the Twitter API - it works great however (see below)

    $this->load->spark('restclient/2.1.0');
    $this->load->library('rest');
    $this->rest->initialize(array('server' => 'http://twitter.com/'));
    $username = 'my-username';
    // Pull in an array of tweets
    $tweets = $this->rest->get('statuses/user_timeline/'.$username.'.xml');

This code works great - however the Twitter API documentation recommend using a slightly different approach (see below) - how would I use the newer approach below with this library?

https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2

Solution

  • This should be pretty straightforward as follows:

    $this->load->spark('restclient/2.1.0');
    $this->load->library('rest');
    $this->rest->initialize(array('server' => 'http://api.twitter.com'));
    $username = 'my-username';
    // Pull in an array of tweets
    $tweets = $this->rest->get('/1/statuses/user_timeline.xml?screen_name='.$username);
    

    Unless I'm missing something.

    You can add any of the other querystring parameters listed on the docs page.