8000 Add README section on streaming API · balitax/codebird-php@9972446 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9972446

Browse files
committed
Add README section on streaming API
1 parent 8a4433a commit 9972446

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
- OpenSSL extension
2424

2525

26+
Summary
27+
-------
28+
29+
Use Codebird to connect to the Twitter REST **and Streaming API :sparkles:** from your PHP code.
30+
Codebird supports full 3-way OAuth as well as application-only auth.
31+
32+
2633
Authentication
2734
--------------
2835

@@ -339,6 +346,57 @@ Please note that your OAuth consumer key and secret is shared within
339346
multiple Codebird instances, while the OAuth request and access tokens with their
340347
secrets are *not* shared.
341348

349+
350+
Consuming the Twitter Streaming API
351+
-----------------------------------
352+
353+
The Streaming APIs give developers low latency access to Twitter’s global stream of
354+
Tweet data. A proper implementation of a streaming client will be pushed messages
355+
indicating Tweets and other events have occurred, without any of the overhead
356+
associated with polling a REST endpoint.
357+
358+
To consume one of the available Twitter streams, follow these **two steps:**
359+
360+
```php
361+
// First, create a callback function:
362+
363+
function some_callback($message)
364+
{
365+
// gets called for every new streamed message
366+
367+
print_r($message);
368+
flush();
369+
370+
// return false to continue streaming
371+
// return true to close the stream
372+
373+
// close streaming after 1 minute for this sample
374+
if (false /* some condition to close the stream */) {
375+
return true;
376+
}
377+
378+
return false;
379+
}
380+
381+
// set the streaming callback in Codebird
382+
$cb->setStreamingCallback('some_callback');
383+
384+
// any callable is accepted:
385+
// $cb->setStreamingCallback(['MyClass', 'some_callback']);
386+
```
387+
388+
```php
389+
// Second, start consuming the stream:
390+
$reply = $cb->user();
391+
392+
// See the *Mapping API methods to Codebird function calls* section for method names.
393+
// $reply = $cb->statuses_filter('track=Windows');
394+
```
395+
396+
Find more information on the [Streaming API](https://dev.twitter.com/streaming/overview)
397+
in the developer documentation website.
398+
399+
342400
How Do I…?
343401
----------
344402

0 commit comments

Comments
 (0)
0