从Facebook页面构建JSON数据

时间:2015-04-26 12:39:15

标签: php json

我正在尝试从Facebook页面中提取数据,到目前为止我已经设法以JSON格式从页面收集数据,但是我希望这些数据以可呈现的方式显示。有人会向我提供任何技术或我的下一步应该是什么?

我目前的代码如下:

$pageIdPosition = strripos($_POST["URL"], '/');
$pageIdStop = strripos($_POST["URL"], '?');
$pageId = substr($_POST["URL"], $pageIdPosition +1);

echo $pageId;
echo "<br />\n";
echo "<br />\n";

// create a new cURL resource

$url = "http://graph.facebook.com/" . $pageId . "posts";

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// grab URL and pass it to the browser
curl_exec($ch);

$res = curl_exec($ch);
var_dump($res);

// close cURL resource, and free up system resources
curl_close($ch);

1 个答案:

答案 0 :(得分:3)

您可以在底部添加:

$resArr = json_decode($res, 1); // decodes the json string to an array echo $resArr['id'] // outputs the id from your json result

http://php.net/manual/en/function.json-decode.php

相关问题