Problem implementing API in php


#1

Am trying to implement datasift streaming API in php but getting follow errors.

First one is:
Warning: assert(): Assertion failed in C:\Program Files (x86)\EasyPHP-12.1\www\lib\datasift.php on line 74

Second one is:
An error has occured : Your event handler object must implement the DataSift_IStreamConsumerEventHandler interface.
Fatal error: Cannot break/continue 1 level in C:\Program Files (x86)\EasyPHP-12.1\www\index.php on line 14

Program code:

<?php require '/lib/datasift.php'; require '/config.php'; date_default_timezone_set('Europe/London'); $user = new DataSift_User(USERNAME, API_KEY); $def = $user->createDefinition('twitter.text contains "coffee" AND twitter.place.country exists'); try { $consumer = $def->getConsumer(DataSift_StreamConsumer::TYPE_HTTP, 'display', 'stopped'); $consumer->consume(); } catch (Exception $e) { echo 'An error has occured : '.$e->getMessage(); break; } function display($consumer, $data) { echo "\n@".$data['twitter']['user']['screen_name']."\n"; echo $data['twitter']['place']['country']."\n"; echo $data['twitter']['text']."\n--"; } function stopped($consumer, $reason) { echo "\nStream stopped : ".$reason."\n"; } ?>

Any help would be appreciated.


#2

This looks like you are trying to use a much older version of our PHP Client Library.

Could you try updating to the latest version, and try running an example such as the football.php example to see if you continue to experience the same problems?


#3

I have encountered the same result using the current standard files on GIT hub downloaded today and the generated example per the API documentation.

<?php require 'includes/lib/datasift.php'; $user = new DataSift_User('**removed for security**', '**removed for security**'); $consumer = $user->getConsumer(DataSift_StreamConsumer::TYPE_HTTP, '**removed for security**', 'display', 'stopped'); $consumer->consume(); function display($consumer, $interaction) { echo $interaction['interaction']['content']."\n--\n"; } function stopped($consumer, $reason) { echo "\nStopped: $reason\n\n"; } ?>
Page displays the following:

Fatal error: Uncaught exception 'DataSift_Exception_InvalidData' with message 'Your event handler object must implement the DataSift_IStreamConsumerEventHandler interface.' in /public_html/includes/lib/DataSift/StreamConsumer.php:135 Stack trace: #0 /public_html/includes/lib/DataSift/StreamConsumer/HTTP.php(68): DataSift_StreamConsumer->__construct(Object(DataSift_User), Object(DataSift_Definition), 'display') #1 /public_html/includes/lib/DataSift/StreamConsumer.php(89): DataSift_StreamConsumer_HTTP->__construct(Object(DataSift_User), Object(DataSift_Definition), 'display') #2 /public_html/includes/lib/DataSift/User.php(273): DataSift_StreamConsumer::factory(Object(DataSift_User), 'HTTP', Object(DataSift_Definition), 'display') #3 /public_html/apitest.php(5): DataSift_User->getConsumer('HTTP', '177e8b23f93a279...', 'display', 'stopped') #4 {main} thrown in /public_html/includes/lib/DataSift/StreamConsumer.php on line 135

Shouldn't the page load the exception handling itself from the "require", either via the SPL loader, or the datasift autoloader? any idea why the DataSift_IStreamConsumerEventHandler on line 42 of datasift.php is not loading?

#4

It looks like you're not implementing the DataSift_IStreamConsumerEventHandler at all. Take a look at how it should be defined on line 25 of our football.php example. 

Can you confirm which version of the client library you are using? (This can be found under the Changelog section of the README) - The current version is v.2.1.1. 


#5

Indeed the football was able to address all the handler issues. Thank you