2012-10-11 153 views
1

我的代码:无法打开流:HTTP请求失败! HTTP/1.1 400错误的请求在

function jsonCall() 
{ 

    global $_SESSION; 
    global $smarty; 

    $client_id = "XXXXXXXX"; 
    $next_max_tag_id = 1349756086082; 

    if(isset($_POST['nextSubmit'])) 
     { 
      $next_max_tag_id = $_POST['next_max_tag_id']; 
     } 


    $url ='https://api.instagram.com/v1/tags/' . $_SESSION['zoekterm'] . '/media/recent?access_token=145408254.f59def8.448ef83c8fa740aa9744a0c47766a857&max_tag_id=' . $next_max_tag_id; 

    $json = file_get_contents($url); 
    $json_output = json_decode($json,true); 

    file_put_contents('json/instagram.json',$json); 

    $imagesErbuiten = array(); 

      foreach($json_output['data'] as $data) 
      { 
       foreach($data['images'] as $images) 
       { 
        array_push($imagesErbuiten, $images); 
       } 
      } 


    $smarty->assign('arrData',$imagesErbuiten); 
    $smarty->assign('next_max_tag_id',$json_output['pagination']['next_max_tag_id']); 
} 

我与Instagram的API和Flickr API工作。当他们在他们的搜索字段中不知道的值时,他们都会得到相同的错误。

举个例子:

的Instagram不允许搜索由像色情,山雀标签,......发生这种情况时,你得到的400错误的请求。当您搜索QSDFQSDFQSDFQSDF(不存在以太网)时,没有错误,仅仅因为搜索有效但数组为空(这很好,所以我可以显示“Nothing has found”)。

这不是空的空间问题。我已经排除了所有的空格,并用+来替换它们。

我的问题:

是否可以删除或修复此错误?一切工作正常,除非你在页面顶部出现这个丑陋的错误。

问候, W.

回答

3

一种替代方法是使用卷曲(http://php.net/manual/en/book.curl.php),以获得更多详细的打印前的请求:

一些这样也许可以帮助你:

function url_get_contents ($Url) { 
    if (!function_exists('curl_init')){ 
     die('CURL is not installed!'); 
    } 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $Url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $output = curl_exec($ch); 
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get the code of request 
    curl_close($ch); 

    if($httpCode == 400) 
     return 'No donuts for you.'; 

    if($httpCode == 200) //is ok? 
     return $output; 


} 
+0

完美地帮助了。他们现在得到的回应是: “你这个坏男孩!不要在这里搜索色情! 你现在会看到一些流行的instapics。” 我也有一个403坏请求,所以我可以修复那一个。你刚刚帮助了5个同样问题的学生(和一位老师)。非常感谢你! –

+1

=)很高兴。 – gvsrepins

相关问题