我的服务器似乎出问题了。我收到了这个错误。
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
这是我已经实现了一年多的代码,并且已确认可以在单独的暂存服务器上运行。
$url = 'http://graph.facebook.com/10150624051911279/photos/all';
$response = json_decode(file_get_contents($url, true));
foreach ($response->data as $photo) {
echo '<li><a href="' . $photo->link . '" ><img class="img" src="timthumb.php?src=' . $photo->source . '&h=175&w=175" /></a></li>';
}
我的服务器上可能出现的故障导致了这个问题。我很难过。
最佳答案
请求应该会失败,因为要访问该 URL,您需要获取访问 token 。所以 Facebook 回来了
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException",
"code": 104
}
}
以及“400 错误请求”状态。此外,由于您打开的是 URL,file_get_contents 的第二个参数应该为 false(如果您知道包含路径不存在,则没有必要搜索包含路径)。
要仍然从 Facebook 获得响应并忽略错误,您可以执行以下操作:
$url = 'http://graph.facebook.com/10150624051911279/photos/all';
$context = stream_context_create(array(
'http' => array(
'ignore_errors'=>true,
'method'=>'GET'
// for more options check http://www.php.net/manual/en/context.http.php
)
));
$response = json_decode(file_get_contents($url, false, $context));
关于php - 无法打开流 : HTTP request failed! HTTP/1.0 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16110176/