PHP code example of spatie / twitter-streaming-api
1. Go to this page and download the library: Download spatie/twitter-streaming-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/ */
spatie / twitter-streaming-api example snippets
PublicStream::create(
$bearerToken,
$apiKey,
$apiSecretKey
)->whenHears('@spatie_be', function(array $tweet) {
echo "We got mentioned by {$tweet['user']['screen_name']} who tweeted {$tweet['text']}";
})->startListening();
PublicStream::create(
$bearerToken,
$apiKey,
$apiSecretKey
)->whenHears('@spatie_be', function(array $tweet) {
echo "We got mentioned by {$tweet['user']['screen_name']} who tweeted {$tweet['text']}";
})->startListening();
PublicStream::create(
$bearerToken,
$apiKey,
$apiSecretKey
)->whenFrom([
[-122.75, 36.8, -121.75, 37.8], // San Francisco
[-74, 40, -73, 41], // New York
], function(array $tweet) {
echo "{$tweet['user']['screen_name']} just tweeted {$tweet['text']} from SF or NYC";
})->startListening();
PublicStream::create(
$bearerToken,
$apiKey,
$apiSecretKey
)->whenFrom([
[-180, -90, 180, 90] // Whole world
], function(array $tweet) {
echo "{$tweet['user']['screen_name']} just tweeted {$tweet['text']} with a location attached";
})->startListening();