这个错误给我带来了麻烦,我知道它需要一个对象,并且已经在论坛中搜索过,并且在试图应用修复程序时失败了,这可能是几行代码很容易修复的。如果有人有时间帮我解决这个问题,我很感激。
再说一遍,这可能是重复的,但我已经尝试了应用补丁,但没有成功。
错误在下面一行中,我将包括我的整个脚本
$response= $TwitterSentinmentAnalysis->sentimentAnalysis($twitterSearchParams);致命错误:在第48行的/Applications/XAMPP/xamppfiles/htdocs/infoCraft-miner/search_server.php中调用非对象上的成员函数sentimentAnalysis()
<?php
// The search terms are passed in the q parameter
// search_server.php?q=[search terms]
if (!empty($_GET['q'])) {
// Remove any hack attempts from input data
$search_terms = htmlspecialchars($_GET['q']);
// Get the application OAuth tokens
require 'app_tokens.php';
//get the datumbox api key
require 'config.php';
require 'lib/TwitterSentimentAnalysis.php';
$TwitterSentimentAnalysis = new TwitterSentimentAnalysis(DATUMBOX_API_KEY,
TWITTER_CONSUMER_KEY,TWITTER_CONSUMER_SECRET,
TWITTER_ACCESS_KEY,TWITTER_ACCESS_SECRET);
// Create an OAuth connection
require 'tmhOAuth.php';
$connection = new tmhOAuth(array(
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'user_token' => $user_token,
'user_secret' => $user_secret
));
// Request the most recent 100 matching tweets
$http_code = $connection->request('GET',$connection->url('1.1/search/tweets'),
$twitterSearchParams=array('q' => $search_terms,
'count' => 100,
'lang' => 'en',
'type' => 'recent'));
// Search was successful
if ($http_code == 200) {
// Extract the tweets from the API response
$response = json_decode($connection->response['response'],true);
global $TwitterSentinmentAnalysis;
//Response to be sent to Sentiment API
$response= $TwitterSentinmentAnalysis->sentimentAnalysis($twitterSearchParams);
$tweet_data = $response['statuses'];
//Sending the Twitter API response(JSONP) direct to a local file
$file = 'data.json';
file_put_contents( 'data.json', json_encode($response));
// Load the template for tweet display
$tweet_template= file_get_contents('tweet_template.html');
// Load the library of tweet display functions
require 'display_lib.php';
// Create a stream of formatted tweets as HTML
$tweet_stream = '';
foreach($tweet_data as $tweet) {
//if loop to change text color
$color=NULL;
if($tweet['sentiment']=='positive'){
$color='#00FF00';
}
else if($tweet['sentiment']=='negative'){
$color='#FF0000';
}
else if($tweet['sentiment']=='neutral'){
$color='#FFFFFF';
}
// Ignore any retweets
if (isset($tweet['retweeted_status'])) {
continue;
}
// Get a fresh copy of the tweet template
$tweet_html = $tweet_template;
// Insert this tweet into the html
$tweet_html = str_replace('[screen_name]',
$tweet['user']['screen_name'],$tweet_html);
$tweet_html = str_replace('[name]',
$tweet['user']['name'],$tweet_html);
$tweet_html = str_replace('[profile_image_url]',
$tweet['user']['profile_image_url'],$tweet_html);
$tweet_html = str_replace('[tweet_id]',
$tweet['id'],$tweet_html);
$tweet_html = str_replace('[tweet_text]',
linkify($tweet['text']),$tweet_html);
$tweet_html = str_replace('[created_at]',
twitter_time($tweet['created_at']),$tweet_html);
$tweet_html = str_replace('[retweet_count]',
$tweet['retweet_count'],$tweet_html);
// Add the HTML for this tweet to the stream
$tweet_stream .= $tweet_html;
}
// Pass the tweets HTML back to the Ajax request
print $tweet_stream;
// Handle errors from API request
} else {
if ($http_code == 429) {
print 'Error: Twitter API rate limit reached';
} else {
print 'Error: Twitter was not able to process that search';
}
}
} else {
print 'No search terms found';
}
?>这是它从TwitterSentimentAnalysis.php调用函数的文件
public function sentimentAnalysis($twitterSearchParams) {
$tweets=$this->getTweets($twitterSearchParams);
return $this->findSentiment($tweets);
}
/**发布于 2016-03-27 01:21:42
在我看来,您的变量命名中有一个错误(这就是为什么删除全局关键字会抛出一个通知)。
当您第一次定义对象时,它如下所示:
$TwitterSentimentAnalysis = new TwitterSentimentAnalysis(DATUMBOX_API_KEY,
TWITTER_CONSUMER_KEY,TWITTER_CONSUMER_SECRET,
TWITTER_ACCESS_KEY,TWITTER_ACCESS_SECRET);那就是$TwitterSentimentAnalysis。不过,您稍后将其引用为$TwitterSentinmentAnalysis。这是微妙的,但在第二个情感中有一个额外的n。
继续调整变量名,删除global行,因为据我所知,这是不必要的(而且,一个更傲慢的开发人员可能甚至会说全局变量是糟糕的形式),我认为您做得很好。
https://stackoverflow.com/questions/36242771
复制相似问题