用PHP或JS访问Facebook页面数据的某种方法 [英] Some way to access Facebook page data with PHP or JS

查看:47
本文介绍了用PHP或JS访问Facebook页面数据的某种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要访问的Facebook页面供稿:

I have a Facebook page feed that I want to access:

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

当我将URL放在浏览器中时,它可以正常工作,但是当我尝试使用file_get_contents访问它时,Facebook会将我发送到一个页面,该页面显示我正在使用不受支持的浏览器.尽管此数据是公开的,所以我不需要访问令牌即可获取它.我需要采取其他步骤才能访问此数据吗?我也尝试使用cURL失败.

When I put the URL in the browser, it works just fine, but when I try to access it using file_get_contents, Facebook sends me to a page that says I am using an unsupported browser. This data is public though so I shouldn't need an access token to obtain it. Is there an extra step I need to take in order to access this data? I also tried using cURL with no success.

感谢您的帮助.谢谢.

推荐答案

您可以使用curl并模仿浏览器,

You can use curl and mimic a browser, see this thread on how to do it.

$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;

这篇关于用PHP或JS访问Facebook页面数据的某种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆