doujia1904 2012-10-11 12:01
浏览 202
已采纳

无法打开流:HTTP请求失败! HTTP / 1.1 400 BAD REQUEST in

My code:

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']);
}

I am working with the Instagram API and Flickr API. Both get same errors when there is a value they don't know in their searchfield.

As an example:

Instagram doesn't allow searches by tag like porn, tits, ... When this happens you get the 400 Bad request. When you search for QSDFQSDFQSDFQSDF (which doesn't exist ether) there is no error, just because the search is valid but the array is empty (which is good, so i can display "Nothing has been found").

It's not a empty space problem. I allready excluded all empty spaces and replaced them with a +.

My question:

Is it possible to just drop or fix this error? Everything works fine, except you get that ugly error at the top of my page.

Greetings, W.

  • 写回答

1条回答 默认 最新

  • doushu0591 2012-10-11 12:26
    关注

    One alternative is to use cURL (http://php.net/manual/en/book.curl.php) to get more details about the request before the print:

    Some like this maybe can help you:

    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;
    
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错