Example of StreamingAPI

php

#1

I need an example of how to use the StreamingAPI. I am currently using the REST_API to get hashtag posts, but it only brings up five posts. I know by using the StreamingAPI I can get more, but do not know how to use it.

Sample of code:

<!DOCTYPE HTML>
<html>
<head></head>

<body>
<h1>This is the beginning of the page</h1>
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
//Configurataion
require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "",
    'oauth_access_token_secret' => "",
    'consumer_key' => "",
    'consumer_secret' => ""
);

$url = 'https://stream.twitter.com/1.1/statuses/filter.json';
$requestMethod = "GET";
$getfield = '?track=twitter';
$twitter = new TwitterAPIExchange($settings);
echo $string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
?>
</body>
</html>

My code is a little messed up since I moved stuff around. How can I do this?


#2

I haven’t personally used it but this repo seems to be pretty commonly used and would likely help you: https://github.com/fennb/phirehose