Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从Facebook解析JSON提要_Php_Json_Facebook_Facebook Graph Api - Fatal编程技术网

Php 从Facebook解析JSON提要

Php 从Facebook解析JSON提要,php,json,facebook,facebook-graph-api,Php,Json,Facebook,Facebook Graph Api,我正在制作一个Facebook应用程序,我有大约50个来自以下代码的用户帖子的提要 try { $response = $fb->get('/me/feed?fields=likes{name},message,story,comments{from},from&limit=50'); } catch(Facebook\Exceptions\FacebookResponseException $e) { } catch(Facebook\Exce

我正在制作一个Facebook应用程序,我有大约50个来自以下代码的用户帖子的提要

try {
        $response = $fb->get('/me/feed?fields=likes{name},message,story,comments{from},from&limit=50');

    } catch(Facebook\Exceptions\FacebookResponseException $e) {

    } catch(Facebook\Exceptions\FacebookSDKException $e) {

    }
    $total_posts = array();
    $posts_response = $response->getGraphEdge();
    $response_array = $posts_response->asJson();
我在
$response\u数组中得到以下结果:

[{"message":"testing...","from":{"name":"Ahsan Omer","id":"1060152144046414"},"id":"1060152144046414_1060590920669203","likes":[{"name":"Ahsan Omer","id":"1060152144046414"}],"comments":[{"from":{"name":"Ahsan Omer","id":"1060152144046414"},"id":"1060590920669203_1060622407332721"}]},{"message":"testing...","from":{"name":"Ahsan Omer","id":"1060152144046414"},"id":"1060152144046414_1060530170675278","comments":[{"from":{"name":"Ahsan Omer","id":"1060152144046414"},"id":"1060530170675278_1060622427332719"}]}]

我想列出谁在timeline Feed中发表过帖子,谁喜欢,谁发表过评论,为了需要解析上述回复,我这样做对吗?

你可以很容易地在web上查找这个问题(谷歌是你的朋友),但无论如何,你会得到一个未经测试、可能语法无效的解决方案,但它会让你走的

json_decode将对数组的响应进行解码(由于$post_response->asJson()返回的字符串不是数组,因此您在此处的命名有误导性。使用$decode[0][message],您将访问第一个数组行和列消息


当然,我只展示了50个feed中的两个,我是PHP新手
$decoded = json_decode($response_array, true),
echo $decoded[0][message]