So I am getting this error and I have no clue why. When I run it on the server it's on
, I get a 404 error with a simple request like this.
$json = file_get_contents('https://graph.facebook.com/me?access_token='.LO开发者_开发技巧NGSTRING);
The error is:
function.file-get-contents: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
However, I can paste the URL that I am using with file_get_contents
directly in the browser at the same time and it comes up. So it seems as if Facebook is blocking my server.
Also it works half the time.
Any ideas?
Try cURL, not sure why file_get_contents is unreliable but I have seen the same issue in the past. I use this geturl function to cURL a URL and pass the parameters in as a PHP array
function geturl($url, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params, null, '&'));
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
Which can then be called like so
$url = 'https://www.graph.facebook.com/me';
$params = array('access_token' => '*********************');
$graph_ret = geturl($url, $params);
$json = @file_get_contents('https://graph.facebook.com/me?access_token='.$access_token) or die("ERROR");
use this will help you alot
精彩评论