As you can see in the code, I am trying to execute an FQL query and retrieve results. The query I generate is completely fine because I have tested it through my browser. I first used file_get_contents() to retrieve the webpage but it was gicing me a 400 Bad Request Error. Somebody suggest cURL instead.
The code segment given below gives me false for $query. If I uncomment the urlencode() line, the script goes on and on and hits the maximum execution time limit. What am I doing wrong?
$limit = $start + 100;
$query = "select post_id, created_time, actor_id, message, attachment, comments, likes, type from stream where source_id = $id limit $start, ". $limit;
$url = "https://graph.facebook.com/fql?q=$query&access_token=$token";
//$url = urlencode($url);
echo $url.'<br>';
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_PROXY, "tcp://10.3.3.3:8080");
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Hi!');
$query = curl_exec($curl_handle);
var_dump($query);
curl_close($curl_handle);
edit: Accessing another URL, file_get_contents gave me this error “failed to open stream: Cannot connect to HTTPS server through proxy”. Since this one is also HTTPS, cURL might also be facing the same problem. I thought this might lead to an answer.
For starters, you reuse your
$queryvariable just before you dump it.Second, use urlencode on your (first)
$queryvariable. (Facebooks $token does not need url encoding)edit (does not fit inside in a comment)
I’ve just tried this myself:
This works without problems.
PM me if you want to try this, and I’ll give you the URL. I’m not confortable with releasing this into the wild..
Pherhaps the source is your proxy ..
edit
Aw what the hell .. go nuts! 😉
http://hal.su/on/fbCurlTest.php?token=the%20token&id=the%id&start=0
replace the%20token with your token and replace the%20id with your id.