【发布时间】:2012-06-01 02:40:52
【问题描述】:
我正在使用 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);
感谢任何帮助!
【问题讨论】:
-
是否启用了 php_curl?你可以通过 echo phpinfo() 找到,如果 curl 不存在则找到 curl 这个词
-
您是否尝试过卷曲其他页面以排除您的服务器和facebook之间是否存在问题?
-
是的,我尝试过冰壶谷歌(本地和开发)并且它有效。 Facebook 可以在本地工作,但不能在 dev 上工作。