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

无法打开流: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 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决