簡體   English   中英

從Facebook頁面構建JSON數據

[英]Structuring JSON data from Facebook Page

我試圖從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);

您可以在底部添加:

$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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM