Q . Failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request.

Robin Jackson. asked, Apr 14 ' 2016

Hi,

I am getting the below error when trying to hit the api url through php file_get_content function.

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

example : 

$url = 'https://graph.facebook.com/v2.5/23230437118?fields=instant_articles_insights.metric(views).period(day).since(15 days ago).until(now),link,id&access_token=EAAXPRwjA9uQBAH4k1zJgJW';
$facebook_instant_article = file_get_contents($url);

 

  • http-request
  • file-get-contents
  • php-errors

1 Answers

Try the below code :

$url = 'https://graph.facebook.com/v2.5/23230437118?fields=instant_articles_insights.metric(views).period(day).since(15 days ago).until(now),link,id&access_token=EAAXPRwjA9uQBAH4k1zJgJW';

$url = preg_replace("/ /", "%20", $url);
$facebook_instant_article = file_get_contents($url);

 

Leave a Ansewer