jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
776 stars 234 forks source link

Streaming API Public Streams #173

Closed Ernest-H closed 8 years ago

Ernest-H commented 8 years ago

Hey, I'm trying to use the streaming API to fetch tweets from a certain hash tag as they come in. i understand that i have to use the 'statuses/filter' request of the public streams from the streaming API but i'm having trouble translating that in code bird.

With the Streaming API example provided i recognized that the user streams from the streaming API is being used and that works fine for me(I'm getting a stream of my twitter account). However changing $reply = $cb->user(); to $reply = $cb->public(); causes the error

" Uncaught Exception: Can't find HTTP method to use for 'public' "

i also tried just using $reply = $cb->public_statuses_filter('track=#jiggajagga'); which returns the same error and $reply = $cb->statuses_filter('track=#jiggajagga'); which returns nothing, no error and no tweets just nothing. Any help would be greatly appreciated Below is my full code

`require_once('codebird.php');

\Codebird\Codebird::setConsumerKey('Co*******', 'PQ*******');
$cb = \Codebird\Codebird::getInstance();

$cb->setToken('3*******', '********');

// First, create a callback function:

function myTweets($message){
    // gets called for every new streamed message
  // gets called with $message = NULL once per second
    if($message !== null){
        print_r($message);
        flush();

    }

    // return false to continue streaming
  // return true to close the stream

  // close streaming after 1 minute for this simple sample
  // don't rely on globals in your code!
  if (time() - $GLOBALS['time_start'] >= 20) {
    return true;
  }

    return false;
}
// set the streaming callback in Codebird
//$cb->setStreamingCallback('some_callback');
$cb->setStreamingCallback('myTweets');

// any callable is accepted:
// $cb->setStreamingCallback(['MyClass', 'some_callback']);

// for canceling, see callback function body
// not considered good practice in real world!
$GLOBALS['time_start'] = time();

// Second, start consuming the stream:
$reply = $cb->user();

// See the *Mapping API methods to Codebird function calls* section for method names.
//$reply = $cb->statuses_filter('track=Windows');`
Ernest-H commented 8 years ago

Okay i solved the issue it works with just using the $reply = $c->statuses_filter('track=Windows'); apparently windows isn't something person tweet about often