且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

未能打开流:HTTP请求失败! HTTP / 1.0 400错误的请求

更新时间:2022-03-21 23:53:54

请求应该失败,因为访问你需要获得一个访问令牌的网址。所以,Facebook的返回

The request should fail, because to access that URL you need to obtain an access token. So Facebook returns

{
   "error": {
      "message": "An access token is required to request this resource.",
      "type": "OAuthException",
      "code": 104
   }
}

沿着有400错误的请求的地位。此外,因为你打开一个URL的file_get_contents的第二个参数应该是假的(没有一点搜索包含路径,如果你知道它不存在)。

with along with a "400 Bad Request" status. Additionally since you're opening an URL the second parameter of file_get_contents should be false (there is no point to search the include path, if you know it's not there).

要仍然得到来自Facebook的响应,而忽略你能做的错误:

To still get the response from Facebook and ignore the error you can do:

$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));