我有一个PHP脚本,显示在我build立在本地机器上的网站中embedded的Tweets。 当我将该网站上传到IIS 8.0服务器时,PHP脚本不再起作用,并且收到此错误消息:
警告:为第76行的C:\ inetpub \ wwwroot \ i360_new \ footer.php中的foreach()提供的无效参数
脚本是:
<?php ini_set('display_errors', 1); require_once('TwitterAPIExchange.php'); /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array( 'oauth_access_token' => "xxxxx", 'oauth_access_token_secret' => "xxxxx", 'consumer_key' => "xxxxx", 'consumer_secret' => "xxxxx" ); /** Perform a GET request and echo the response **/ /** Note: Set the GET field BEFORE calling buildOauth(); **/ $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $getfield = '?screen_name=interactive360&count=1'; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); $string = json_decode($twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(),$assoc = TRUE); foreach($string as $items) { echo $items['text']."<br />"; } ?>
我认为这可能是一个PHP版本的问题,但我的本地机器运行5.4.10和我的服务器运行5.4.14。
你有没有比较两个服务器phpinfo()? 在几乎相同的环境中运行时,每个服务器可以根据安装的模块而有所不同。
你可能想要确保$ string不是空的。 我相信一个ForEach会抛出这个错误,如果你提供一个空的string。 它看起来像string取决于TwitterAPIExchange.php,我看到“需要一次”,但确保它的configuration正确。
事实certificate这是一个SSL / CURL问题。 在TwitterAPIExchange.php文件中,我不得不将这两行添加到CURL选项数组中:
CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false