【发布时间】:2013-10-01 03:28:13
【问题描述】:
我有一个 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。
【问题讨论】:
-
该服务器是否启用了 JSON 支持?
-
@Hanky웃Panky:你的意思是有人会禁用
json_decode?这甚至可能吗? -
在您的
foreach行之前放置一个var_dump($string)以查看您得到的结果,因为它看起来并不符合您的期望。 -
@Hanky웃Panky 我不确定?我以为是,但如果默认情况下没有启用它,那么我还没有启用 JSON 支持。有具体的方法吗?
-
@dirt 我添加了建议的行,它只是让我的页脚消失了。