我有一个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。
答案 0 :(得分:0)
事实证明这是一个SSL / CURL问题。在TwitterAPIExchange.php文件中,我不得不将这两行添加到CURL选项数组中:
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false