cURL和Facebook问题

时间:2012-05-25 13:57:19

标签: php facebook curl

我正在使用cURL访问Facebook页面。在本地它工作得很完美,但是当我将它上传到我的开发服务器时,它会中断并返回一个空字符串。我已经检查过并且cURL已安装在服务器上。这是我用来访问facebook的代码:

$header = array();
$header[] = 'Accept: text/json';
$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, 'http://facebook.com/feeds/page.php?format=json&id=135137236003');
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);

感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

当facebook将响应标头发送为*/*时,将接受标头更改为application/jsonapplication/json

并更改此网址

http://facebook.com/feeds/page.php?format=json&id=135137236003

http://www.facebook.com/feeds/page.php?format=json&id=135137236003

因为Facebook正在将非www请求重定向到www请求。虽然它适合你,因为放置跟随位置,但它节省了一次reound旅行