PHP code example of redwebcreation / twitter-stream-api
1. Go to this page and download the library: Download redwebcreation/twitter-stream-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
redwebcreation / twitter-stream-api example snippets
$connection = new \Felix\TwitterStream\TwitterConnection(
bearerToken: '...' # the one you got from the Developer Portal
);
$stream = new \Felix\TwitterStream\Streams\VolumeStream();
// or
$stream = new \Felix\TwitterStream\Streams\FilteredStream();
$stream->withTweetLimit(100_000);
$stream->listen($connection, function (object $tweet) {
echo $tweet->data->text . PHP_EOL;
});
use Felix\TwitterStream\Rule\RuleManager;
$rule = new RuleManager($connection);
$rule->save(
# tweets must contain the word cat and have at least one image
"cat has:images",
"images of cats"
);
use Felix\TwitterStream\Rule\Rule;
$rule->saveMany([
new Rule("cats has:images", "cat pictures"),
new Rule("dogs has:images", "dog pictures"),
new Rule("horses has:images", "horse picture"),
]);