尝试修复非对象错误PHP twitter Xampp的属性

尝试修复非对象错误PHP twitter Xampp的属性,php,netbeans,twitter,xampp,Php,Netbeans,Twitter,Xampp,我在c9.io上使用了以下代码,使用TwitterAPI查询和显示tweets,TwitterAPI在c9上完美地显示了tweets。但是,当在我的计算机上使用netbeans和Xampp运行相同的代码时,我得到以下错误 注意:试图在第44行的C:\xampp\htdocs\twitter api php\twitter search.php中获取非对象的属性 警告:为C:\xampp\htdocs\twitter api php\twitter search.php第44行中的foreach(

我在c9.io上使用了以下代码,使用TwitterAPI查询和显示tweets,TwitterAPI在c9上完美地显示了tweets。但是,当在我的计算机上使用netbeans和Xampp运行相同的代码时,我得到以下错误

注意:试图在第44行的C:\xampp\htdocs\twitter api php\twitter search.php中获取非对象的属性

警告:为C:\xampp\htdocs\twitter api php\twitter search.php第44行中的foreach()提供的参数无效“

这是我为twittersearch.php编写的代码。它们的xampp设置是否需要编辑

<html>
<h1>Welcome to Twitter API Search</h1>
<head></head>
<h2>Search tweets containing keywords:</h2>
<body>
<form method="POST">
<input type="text" name="q" size="35" />
<input type="submit" value="Search" />
</form>
</body>
</html>
<?php
#### Include the class file ####
error_reporting(-1);
ini_set('display_errors', true);
require_once('TwitterAPIExchange.php');
if(!empty($_POST['q'])) {

    #### Set access tokens ####

        $settings = array(
            'oauth_access_token' => "83483102-js8XSKtqa8WfQgzuscXzJTZhxWpWXKvYe7XDdrOir",
            'oauth_access_token_secret' => "Vz5grexMBCQwcWj8imZSkwFmpWuKfuIEv3cFzdzQDNPf3",
            'consumer_key' => "zbFgHw7Ne8iRWv9L2UDODw",
            'consumer_secret' => "r6s6lapJvypNT5dHmdJNsCDHriPezWlPWgKz5TauBo"
        );

    #### Choose URL and Request Method ####

        $url = 'https://api.twitter.com/1.1/search/tweets.json';
        $requestMethod = 'GET';
        //$getfield = '?q='.urlencode($_POST['q']);
        $getfield = '?q='.urlencode($_POST['q']);


    #### Perform the request! ####
        $twitter = new TwitterAPIExchange($settings);
        $ret = $twitter->setGetfield($getfield)
                    ->buildOauth($url, $requestMethod)
                     ->performRequest();

    $json = json_decode($ret);
    //var_dump($twitter);
    foreach($json->statuses as $tweet) {
        echo '<b><h2>Tweet: </h2></b>'.$tweet->text.'<br />';
        echo '<b>By: </b>'.$tweet->user->name.'<br /><br />';
    }
}  

欢迎使用Twitter API搜索
搜索包含关键字的推文:
请替换:

foreach($json->statuses as $tweet) {
    echo '<b><h2>Tweet: </h2></b>'.$tweet->text.'<br />';
    echo '<b>By: </b>'.$tweet->user->name.'<br /><br />';
}
foreach($json->状态为$tweet){
回显“Tweet:”.$Tweet->text.“
”; echo“By:”.$tweet->user->name.“

”; }
作者:

if($json->errors){
foreach($json->errors as$error){
echo$error->消息。“
”; } }否则{ foreach($json->状态为$tweet){ 回显“Tweet:”.$Tweet->text.“
”; echo“By:”.$tweet->user->name.“

”; } }
$json->status
不是PHP可以迭代的类型。就在
foreach
循环之前,
var\u dump($json);
的输出是什么?var\u dump($json)返回null,这与指向授权的代码无关。但是,当我在c9.io上运行相同的代码时,它不会显示任何错误,并且正确显示所有tweet。你知道$json对象返回null的原因吗?在用你给我的if-else语句替换我的foreach look之后,我仍然会收到相同的错误“注意:第50行的C:\xampp\htdocs\twitter api php\twitter search.php中尝试获取非对象的属性注意:第55行的C:\xampp\htdocs\twitter api php\twitter search.php中尝试获取非对象的属性警告:第55行的C:\xampp\htdocs\twitter api php\twitter search.php中为foreach()提供的参数无效“请将
var_dump($json)的输出粘贴到这里
if($json->errors){
output:NULL通知:尝试获取第51行C:\xampp\htdocs\twitter api php\twitter search.php中非对象的属性通知:尝试获取第56行C:\xampp\htdocs\twitter api php\twitter search.php中非对象的属性警告:为foreach()提供的参数无效在C:\xampp\htdocs\twitter api php\twittersearch.php中,第56行的curl或json似乎有问题。关于
var\u dump($ret)
,您有什么发现?var\u dump($ret)返回bool(false)
if($json->errors) {
    foreach($json->errors as $error) {
        echo $error->message . '<br/>';
    }
} else {
    foreach($json->statuses as $tweet) {
        echo '<b><h2>Tweet: </h2></b>'.$tweet->text.'<br />';
        echo '<b>By: </b>'.$tweet->user->name.'<br /><br />';
    }        
}