Skip to content
A Twitter API wrapper for Code Igniter
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

License MIT Splint Identifier Splint Version Latest Release Commits

Twitter Logo


This is a Twitter API wrapper for Code Igniter.

Currently, this library can do the following

  • Request Access Tokens
  • Request Bearer Tokens
  • Perform the 3 staged User Authentication
  • Tweet.


To install, download and install Splint from and then run the below from your Code Igniter project root.

splint install francis94c/ci-twitter


From anywhere you can access the CI instance

// Get the below from
$params = array(
  "api_key"             => "api_key_here",
  "api_secret_key"      => "api_secret_key_here",
  "access_token"        => "access_token_here",
  "access_token_secret" => "access_token_secret_here",
  "verify_host"         => true

$this->load->splint("francis94c/ci-twitter", "+Twitter", $params, "twitter");

// OR call initialize() with parameters.

$this->load->splint("francis94c/ci-twitter", "+Twitter", null, "twitter");

OR Alternatively load with the below steps.

  • create a file twitter_config.php in your application/config folder.
  • Add the below contents into the file created above.
defined('BASEPATH') OR exit('No direct script access allowed');

$config["twitter_config"] = array(
  "api_key"             => "api_key_here",
  "api_secret_key"      => "api_secret_key_here",
  "access_token"        => "access_token_here",
  "access_token_secret" => "access_token_secret_here",
  "verify_host"         => true
  • Then load with the single line of code.


3 Staged Authentication Process

After loading the package from a controller, call the function below

$token = $this->twitter->requestToken("https://call_back_url"); //  See for call back urls
if ($token["oauth_callback_confirmed"] == true) redirect($this->twitter->getAuthorizeUrl($token["oauth_token"]));

This will redirect the user to the twitter authorization page. If Authorization is successful, a request will be made to the callback URL of your Twitter App.

In the controller that handles the callback you can then get the access token with the returned oauth_token and the oauth_verifier with the code below

$access_token = $this->twitter->getAccessToken($oauth_token, $oauth_verifier);


// Output:
// array (
//   "oauth_token"        => "6253282-eWudHldSbIaelX7swmsiHImEL4KinwaGloHANdrY",
//   "oauth_token_secret" => "2EEfA6BG3ly3sR3RjE0IBSnlQu4ZrUzPiYKmrkVU",
//   "user_id"            => "6253282",
//   "screen_name"        => "twitterapi"
// )

// You can then use the oauth_token and oauth_token_secret for requests that need /////user authentication.

Get a User's Info

To get a user's info which is most likely needed just after the 3 staged authentication process when implementing a sign up or sign in with twitter, use the below code the request a user's credential using an oauth_token and an oauth_token_secret.

$credentials = $this->twitter->getCredentials($oauth_token, $oauth_token_secret);

See for the key-value structure of $credentials response variable.


To tweet, you simply need an api_key, api_secret_key, access_token and an access_token_secret

Note that access_token and access_token_secret is also referred to as oauth_token and oauth_token_secret. If you've already initialized the API with these values, you can go ahead and tweet with the below code.

$this->twitter->tweet("A Sample Tweet Here.");

This will return true if successful, or false otherwise.

Please see the Wiki at for proper documentation of package methods.

You can’t perform that action at this time.