Weird behavior of curl and facebook
Here is the code:
$ch = curl_init( 'https://graph.facebook.com/btaylor');
curl_setopt( $ch, CURLOPT_USERAGENT, '' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER ,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
print_r( $data) ;
curl_close($ch);
It shows few informations from facebook. It works on my localhost,开发者_如何学Python but when I try to run it on my server it just doesn't work, returns a blank site. I tried to use this code with others sites like example.com and It works, so I thought, that its becouse of facebook blocks my ip (i dont know why it would be true), so I checked it. I have run it with
curl_setopt($ch, CURLOPT_PROXY, 'myproxy');
But it still doesn't show any information. I am trying to fix it all day, but its too difficult. Have you got some ideas?
I'm going to guess that either curl isn't installed on your server and/or error reporting is disabled / turned down on your server.
Edit: Okay, if you know curl is installed and works, you still need to enable error reporting. When you finally see your error about "certificate verify failed," you'll need to export a X.509 Certificate (PEM) from Facebook and configure curl to trust it.
Or, if this isn't production code, you can just use (the insanely insecure):
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
... to blindly accept Certificate Authorities.
精彩评论