使用PHP或JS访问Facebook页面数据的某种方法


Some way to access Facebook page data with PHP or JS

我有一个想要访问的Facebook页面提要:

http://facebook.com/feeds/page.php?format=json&id=123456789 (Not a real ID)

当我将URL放入浏览器中时,它工作正常,但是当我尝试使用file_get_contents访问它时,Facebook会将我发送到一个页面,该页面显示我正在使用不受支持的浏览器。此数据是公开的,因此我不需要访问令牌即可获取它。我是否需要采取额外的步骤才能访问此数据?我也尝试使用cURL,但没有成功。

任何帮助,不胜感激。谢谢。

您可以使用 curl 并模仿浏览器,请参阅此线程了解如何操作。

$header = array();
$header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$header[] = 'Cache-Control: max-age=0';
$header[] = 'Connection: keep-alive';
$header[] = 'Keep-Alive: 300';
$header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
$header[] = 'Accept-Language: en-us,en;q=0.5';
$header[] = 'Pragma: ';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'YOUR URL HERE');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close ($ch);
echo $result;

不要使用这个网址,访问它真的是非常古老的方法。使用他们相对较新的图形 API