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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记