-1

可能重复:
foreach 中的参数无效

我只是想解析 FB graphi API 结果。

当我尝试 foarch 循环时,我得到 Invalid Argument 错误

这是代码

$url = urlencode("http://***.com/pages/view?id=2153&item=Mens-Collection-Shoes");

$request_url ="https://graph.facebook.com/comments/?ids=".$url;
$requests = file_get_contents($request_url);
$fb_response = json_decode($requests, true);

foreach($fb_response->data as $item){
echo $item->message . '<br />';
echo $item->from->id . '<br />';
echo $item->from->name . '<br />';
echo $item->message . '<br />';
echo $item->created_time . '<br /><br />';
}

当我转储时$requests,我得到(由我格式化):

{"http:\/\/***.com\/pages\/view?id=2153&item=Mens-Collection-Shoes":
{"comments":
{"data":[
{"id":"***_78606","from":
{
"name":"Laura","id":"***"},
"message":"I love these.",
"can_remove":
false,
"created_time":"2012-11-20T10:20:16+0000",
"like_count":0,
"user_likes":false
}],
"paging":{
"next":"https:\/\/graph.facebook.com\/***\/comments?limit=25&offset=25&__after_id=***_78606"
}}}}

有任何想法吗?可能是一些我看不到的简单的东西

尝试过有无urlencode但没有区别

4

1 回答 1

1

我相信

json_decode($blah, TRUE)

返回一个数组......不是一个对象,尝试从

$fb_response = json_decode($requests, true);

于 2012-11-20T12:19:03.520 回答