我正试图从Facebook收集信息,通过Graph API Explorer自动推送到页面.
我有curl请求工作,它给我有效的JSON(用验证器检查).
我收到以下错误:警告:为foreach()提供的参数无效
如果我执行var_dump,则将其声明为字符串.
PHP:
$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url, CURLOPT_HEADER =>false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, )); $response = curl_exec($curl); curl_close($curl); foreach($response as $posts){ if($posts['from']['id']='230594106985291'){ echo ""; echo $posts['message']; echo ""; } }
此处列出的样本卷曲响应:http://jsfiddle.net/X933V/
我认为你只需要decode your json
在循环之前作为一个数组
$response = curl_exec($curl); curl_close($curl); $json = json_decode($response, true); //note the second parameter true //to have decoded as an associative array foreach($json as $posts){