forked from themattharris/tmhOAuth-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitestream.php
50 lines (45 loc) · 1.7 KB
/
sitestream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Very basic Site Streams example. In production you would store the
* received tweets in a queue or database for later processing.
*
* Site Streams require you to use the user token/secret of the owner
* of the application.
*
* Instructions:
* 1) If you don't have one already, create a Twitter application on
* https://dev.twitter.com/apps
* 2) From the application details page copy the consumer key and consumer
* secret into the place in this code marked with (YOUR_CONSUMER_KEY
* and YOUR_CONSUMER_SECRET)
* 3) From the application details page copy the access token and access token
* secret into the place in this code marked with (A_USER_TOKEN
* and A_USER_SECRET)
* 4) In a terminal or server type:
* php /path/to/here/sitestream.php
* 5) To stop the Streaming API either press CTRL-C or, in the folder the
* script is running from type:
* touch STOP
*
* @author themattharris
*/
function my_streaming_callback($data, $length, $metrics) {
echo $data .PHP_EOL;
return file_exists(dirname(__FILE__) . '/STOP');
}
require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'YOUR_CONSUMER_KEY',
'consumer_secret' => 'YOUR_CONSUMER_SECRET',
'user_token' => 'A_USER_TOKEN',
'user_secret' => 'A_USER_SECRET',
));
$method = "https://sitestream.twitter.com/2b/site.json";
$params = array(
// comma seperated list of user_ids who have authorised your application through OAuth
'follow' => '777925'
);
$tmhOAuth->streaming_request('POST', $method, $params, 'my_streaming_callback');
// output any response we get back AFTER the Stream has stopped -- or it errors
tmhUtilities::pr($tmhOAuth);