English 中文(简体)
cURL和Facebook问题
原标题:cURL and Facebook problems

我正使用 CURL 访问Facebook页面。 本地操作完美, 但当我上传到 Dev 服务器时, 它会折断并返回一个空字符串。 我检查过, 并在服务器上安装了 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);

任何帮助都感激不尽!

最佳回答

将接受信头更改为 application/json ,因为Facebook正在将回复信头发送为 application/json

改变这个骨灰

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

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

as facebook is redirecting the non-www request 至 www requests. Though it works for you as put follow location, but it saves one reound trip

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...