2012-10-11 168 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

相關問題