无法打开流:HTTP请求失败! HTTP / 1.0 400错误请求

It seems out of no where my server is acting up. and I'm getting this error.

    failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

This is my code that I've had implemented for over a year now, and is confirmed working on a separate staging server.

    $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>';
}

What could possibly be failing on my server to cause this issue. I'm stumped.

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
   }
}

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).

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