Twitter APi Library for Codeigniter

Download Api Library for codeigniter

https://github.com/ElliottLandsborough/Codeigniter-Twitter-Search-Library

After this place this library in system folder

After create config file and place this folder config/twitter.php

Add this code in config file

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| TWITTER CONFIG
| -------------------------------------------------------------------
*/

// required only for streaming api
$config['user'] = 'twitter-username';
$config['pass'] = 'twitter-password';

// required only for api v1.1 search
$config['consumer_token']  = 'abcdefghijklmnopqrstuvwxyz';
$config['consumer_secret'] = 'abcdefghijklmnopqrstuvwxyz';
$config['access_token']    = 'abcdefghijklmnopqrstuvwxyz';
$config['access_secret']   = 'abcdefghijklmnopqrstuvwxyz';
?>

 

Now make controller file

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* A collection of functions to be run through command line only.
*/
class Findtweets extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        // set maximum execution time to infinity
        set_time_limit(0);
        $this->load->library('twitterlib');
    }

    // stream tweets from twitter livestream
    public function stream()
    {
        $this->twitterlib->stream();
    }

    // search for tweets by hashtag
    public function search($cachetime=null)
    {
        $this->twitterlib->search($cachetime);
    }

    // search for tweets by hashtag using api v1.1
    public function searchone($cachetime=null)
    {
      $this->twitterlib->searchone($cachetime);
    }
}
?>

 

Now create database

CREATE TABLE IF NOT EXISTS `search_terms` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `term` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

INSERT INTO `search_terms` (`id`, `term`) VALUES 
(1, 'yolo'),
(2, 'fact');

CREATE TABLE IF NOT EXISTS `tweets` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `tweet_id` text NOT NULL,
  `user_id` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s