forked from themattharris/tmhOAuthExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreaming_api.php
More file actions
28 lines (23 loc) · 770 Bytes
/
streaming_api.php
File metadata and controls
28 lines (23 loc) · 770 Bytes
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
<?php
require __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tmhOAuthExample.php';
$tmhOAuth = new tmhOAuthExample();
function my_streaming_callback($data, $length, $metrics) {
$file = __DIR__.'/metrics.txt';
echo $data .PHP_EOL;
if (!is_null($metrics)) {
if (!file_exists($file)) {
$line = 'time' . "\t" . implode("\t", array_keys($metrics)) . PHP_EOL;
file_put_contents($file, $line);
}
$line = time() . "\t" . implode("\t", $metrics) . PHP_EOL;
file_put_contents($file, $line, FILE_APPEND);
}
return file_exists(dirname(__FILE__) . '/STOP');
}
$code = $tmhOAuth->streaming_request(
'GET',
'https://stream.twitter.com/1.1/statuses/sample.json',
array(),
'my_streaming_callback'
);
$tmhOAuth->render_response();