Phirehose Not Connecting

53 views
Skip to first unread message

anders...@me.com

unread,
May 10, 2016, 5:24:31 AM5/10/16
to Phirehose Users
Hi all,

I have an issue with Phirehose. I have experience using the REST API, but I am new to Phirehose (hence this might be naivety on my part). I am trying to stream data from the streaming API.

I have tried entering my credentials in the example code - "phirehose-master/example/sample.php". However, when executing the script, the page appears to be loading, but none of the data is printed on the screen. Is this correct?

I am using the below code (I have removed credentials for privacy, however these were added and it still does not work).

Thanks in advance.

<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');

/**
 * Example of using Phirehose to display the 'sample' twitter stream.
 */
class SampleConsumer extends OauthPhirehose
{
  /**
   * Enqueue each status
   *
   * @param string $status
   */
  public function enqueueStatus($status)
  {
    /*
     * In this simple example, we will just display to STDOUT rather than enqueue.
     * NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
     *       enqueued and processed asyncronously from the collection process.
     */
    $data = json_decode($status, true);
    if (is_array($data) && isset($data['user']['screen_name'])) {
      print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
    }
  }
}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "REMOVED");
define("TWITTER_CONSUMER_SECRET", "REMOVED");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "REMOVED");
define("OAUTH_SECRET", "REMOVED");

// Start streaming
$sc = new SampleConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_SAMPLE);
$sc->consume();

Darren Cook

unread,
May 10, 2016, 6:29:03 AM5/10/16
to phireho...@googlegroups.com
> I have tried entering my credentials in the example code -
> "phirehose-master/example/sample.php". However, when executing the script, the
> page appears to be loading, ...

"the page" meaning a web page, where you are using phirehose? If so,
don't do that: phirehose scripts should be run from the commandline, not
through a browser.

(They are designed to be running 24/7, and if you try to connect too
frequently to Twitter, they will quickly block you.)

> but none of the data is printed on the screen. Is this correct?

Your code should be printing them. (enqueueStatus() is called for each
tweet that arrives, as soon as it arrives.) "METHOD_SAMPLE" corresponds
to this API call:
https://dev.twitter.com/streaming/reference/get/statuses/sample

Darren


anders...@me.com

unread,
May 10, 2016, 8:33:22 AM5/10/16
to Phirehose Users
Hi Darren.

Thanks for letting me know. I was previously trying to execute this script on a web server. Are you suggesting it would be best to run this 24/7 from a command line on a virtual machine? Or is this something i can still do on my webserver within cpanel?

I have managed to connect successfully through a curl request via the command line using the signature generator here - https://dev.twitter.com/streaming/reference/get/user.

However i am now wondering how i can execute this script and make actions off the back of the returned data?

My end goal is to essentially interpret when a user tweets my handle, and then automatically tweet them a reply. So i need to connect to the API to receive the data, and then interpret it somehow so i can automatically reply to each tweet.

All i have achieved so far is connecting via a curl request, i have not yet successfully achieved this with Phirehose.

Really appreciate your help.

Thanks.
Luke

Karthik Murugan

unread,
May 10, 2016, 10:59:45 AM5/10/16
to phireho...@googlegroups.com

If you're using user streams, please change version in URL from /2/ to /1.1/. I think it's in phirehose.php

--

---
You received this message because you are subscribed to the Google Groups "Phirehose Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phirehose-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Darren Cook

unread,
May 10, 2016, 11:40:23 AM5/10/16
to phireho...@googlegroups.com
> web server. Are you suggesting it would be best to run this 24/7 from a command
> line on a virtual machine?

Yes.

> Or is this something i can still do on my webserver within cpanel?

Not within cpanel; at least not without getting complex. A virtual host
is $10/month, so going the complex route is never going to be worth it.

> However i am now wondering how i can execute this script and make actions off
> the back of the returned data?

The recommended way is to that the phirehose script write the tweets to
a database (which could be a csv file, or an in-memory queue, etc.),
then have another script (which can be run from a web server) access
them from that database.

Karthik Murugan wrote:
> If you're using user streams, please change version in URL from /2/ to /1.1/. I
> think it's in phirehose.php

The Phirehose::METHOD_SAMPLE command you were testing with is using 1.1,
so that won't be the issue.

But Karthik's point is good: for what you want to do, you want to be
using user streams. So either get the very latest version of Phirehose
from git, or find and replace the /2/ with /1.1/

Darren

anders...@me.com

unread,
May 10, 2016, 11:50:10 AM5/10/16
to Phirehose Users
Thanks for all the info. I will try all of the above.

I have downloading the most recent version of phirehose (today) - i was aware the endpoint had changed, however i was under the impression these had all been changed as of a while ago?

Thanks again all.

Luke
Reply all
Reply to author
Forward
0 new messages