public function TwitterSentiment($tweet_text) { require_once 'DatumboxAPI.php'; $api_key = 'd4a4b20a7ed191960a123464873ebfb4'; $DatumboxAPI = new DatumboxAPI($api_key); // PHP makes problems with "@" in HTTP POST --> workaround. $tweet_escaped = addcslashes($tweet_text, '@'); $DocumentClassification['TwitterSentimentAnalysis'] = $DatumboxAPI->TwitterSentimentAnalysis($tweet_escaped); unset($DatumboxAPI); //Return the result if (isset($DocumentClassification['TwitterSentimentAnalysis'])) { return $DocumentClassification['TwitterSentimentAnalysis']; } else { return "none"; } }
protected function findSentiment($tweets) { $DatumboxAPI = new DatumboxAPI($this->datumbox_api_key); //initialize the DatumboxAPI client $results = array(); foreach ($tweets['statuses'] as $tweet) { //foreach of the tweets that we received if (isset($tweet['metadata']['iso_language_code']) && $tweet['metadata']['iso_language_code'] == 'en') { //perform sentiment analysis only for the English Tweets $sentiment = $DatumboxAPI->TwitterSentimentAnalysis($tweet['text']); //call Datumbox service to get the sentiment if ($sentiment != false) { //if the sentiment is not false, the API call was successful. $results[] = array('id' => $tweet['id_str'], 'user' => $tweet['user']['name'], 'time' => $tweet['created_at'], 'text' => $tweet['text'], 'url' => 'https://twitter.com/' . $tweet['user']['name'] . '/status/' . $tweet['id_str'], 'sentiment' => $sentiment); } } } unset($tweets); unset($DatumboxAPI); return $results; }