Beispiel #1
0
 public function __construct()
 {
     $this->config = Zend_Registry::get('config');
     \Codebird\Codebird::setConsumerKey($this->config->twitter->consumerKey, $this->config->twitter->consumerSecret);
     $this->cb = \Codebird\Codebird::getInstance();
     if (isset($this->config->twitter->bearerToken)) {
         $bearerToken = $this->config->twitter->bearerToken;
     } else {
         $bearerToken = $this->_fetchBearerToken();
     }
     \Codebird\Codebird::setBearerToken($bearerToken);
 }
Beispiel #2
0
<?php

require_once 'codebird.php';
\Codebird\Codebird::setConsumerKey('oyptgFh88tVBmhXBSywcoeImQ', 'sFhwc99LjYbDxdvHZQfUPscQv6pqiP35kdAdldIclgybS5imKJ');
// static, see 'Using multiple Codebird instances'
$cb = \Codebird\Codebird::getInstance();
$cb->setToken('310088233-nlHAOtTbQVKBZq1CsUmMpjSekI1zvsbtBcgTlOnw', 'qsb8XFDBvL7bmQ1X006iMU7gmLw6EE7fr4nJODzYGnDLr');
$reply = $cb->oauth2_token();
if (isset($reply->errors)) {
    echo $reply->errors[0]->message;
} else {
    $bearer_token = $reply->access_token;
    \Codebird\Codebird::setBearerToken($bearer_token);
    $params = array('status' => 'Fish & chips woooh');
    $reply = $cb->statuses_update($params);
}
Beispiel #3
0
    /**
     * Construct
     * @access public
     */
    public function __construct() {
        
        // detect server environment
        $root = $_SERVER['DOCUMENT_ROOT'];
        
        $is_local = (strpos($root, 'XAMPP')) ? true : false;
        
        // db
        $options = array(
            Zend_Db::ALLOW_SERIALIZATION => false
        );
        
        $params = array(
            'host'           => 'localhost',
            'username'       => 'sfsb_admin',
            'password'       => 'superdata',
            'dbname'         => 'twitter_tracker',
            'options'        => $options
        );
        
        if($is_local) {
            $params = array(
                'host'           => 'localhost',
                'username'       => 'root',
                'password'       => '',
                'dbname'         => 'twitter_tracker',
                'options'        => $options
            );
        }

        try {
            $this->db = Zend_Db::factory('Pdo_Mysql', $params);
            $this->db->getConnection();
        } catch (Zend_Db_Adapter_Exception $e) {
            // perhaps a failed login credential, or perhaps the RDBMS is not running
            if($is_local) {
//                echo 'failed login credentials\n';
                print_r($e);
            }
        } catch (Zend_Exception $e) {
            // perhaps factory() failed to load the specified Adapter class
            if($is_local) {
//                echo 'failed to load specified adapter class\n';
                print_r($e);
            }
        }
        
        $this->table_name = 'tweets';
        
        // twitter
        // DEPRECATED
//        $this->ts   = new Zend_Service_Twitter_Search('json');
        
        // codebird - for search
        // NOTE: I will try with alex to make this work first, if it's not possible to upgrade php to 5.3 then I will write my own library referencing this:
        // https://github.com/thatericsmith/simple-php-twitter-getter/blob/master/TwitterGetter.php
        \Codebird\Codebird::setConsumerKey('Mr3tmdYJtDUBHFCIi0tPQw', 'yPFzdcuzEj0fc8jwuzrE4LdJhmNGnaiqlfv8aOVwGRU'); // static, see 'Using multiple Codebird instances'
        $cb = \Codebird\Codebird::getInstance();
        $cb->setToken('850078843-rKjQFWOzZzPSUCdEyQIJOHvQo6Yna1ohGP8El83K', 'wE6HRo7mPguFT7atpJGHURUccuW5kXYKvLa1WevS0Y');
        $this->cb = $cb;
        
        $file = "bearer.txt";
        if(file_exists($file)) {
//            echo "using " . $file;
//            echo '<br />';
            $bearer_token = file_get_contents($file);
//            echo "using b token: " . $bearer_token;
//            echo '<br />';
            \Codebird\Codebird::setBearerToken($bearer_token);
        } else {
//            echo "getting new bearer token";
//            echo '<br />';
            $reply = $this->cb->oauth2_token();
            $bearer_token = $reply->access_token;
//            echo "setting new bearer toekn to file: " . $bearer_token;
//            echo '<br />';
            file_put_contents($file, $bearer_token);
        }
        
        $this->bearer_token = $bearer_token;
            
    }