我有一个PHP脚本,它显示嵌入在我在本地机器上构建的网站中的推文。当我将站点上传到我的 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。
事实证明,这是一个SSL/CURL问题。在 TwitterAPIExchange.php 文件中,我不得不将这两行添加到 CURL 选项数组中:
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false