Exemple #1
0
        require_once 'db_lib.php';
        $this->oDB = new db();
    }
    // This function is called automatically by the Phirehose class
    // when a new tweet is received with the JSON data in $status
    public function enqueueStatus($status)
    {
        $tweet_object = json_decode($status);
        // Ignore tweets without a properly formed tweet id value
        if (!isset($tweet_object->id_str)) {
            return;
        }
        $tweet_id = $tweet_object->id_str;
        // If there's a ", ', :, or ; in object elements, serialize() gets corrupted
        // You should also use base64_encode() before saving this
        $raw_tweet = base64_encode(serialize($tweet_object));
        $field_values = 'raw_tweet = "' . $raw_tweet . '", ' . 'tweet_id = ' . $tweet_id;
        $this->oDB->insert('json_cache', $field_values);
    }
}
// Open a persistent connection to the Twitter streaming API
$stream = new Consumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
// Establish a MySQL database connection
$stream->db_connect();
// The keywords for tweet collection are entered here as an array
// More keywords can be added as array elements
// For example: array('recipe','food','cook','restaurant','great meal')
$stream->setTrack(array('#ris_zh', 'tympaan', '#tympaan', '@tympaan_inst', '@Tympaan_inst', 'Tympaan', '#databankzh'));
// Start collecting tweets
// Automatically call enqueueStatus($status) with each tweet's JSON data
$stream->consume();