2016-11-01 2 views
0

スカイスキャナートラベルAPI/200を返し 私は私のAndroidアプリに旅行APIを使用したい429

まずテストハーネスデモAPIキー(prtl6749387986743898559646983194)を返す/プライベートAPIKEYを使用し、セッションに

をセッションとポーリングの作成成功

しかし、DashboardのプライベートAPIキーを使用している間に、それは返す429 Too many request

プライベートAPIキーを使用するために必要なことはありますか?

私のコード:最初の場合

public void run(String u) { 
    try { 
     // SystemClock.sleep(500); 
     url = new URL(u); 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
     connection.setRequestMethod("POST"); 
     connection.setConnectTimeout(50 * 1000); 
     connection.setReadTimeout(50 * 1000); 
     connection.setRequestProperty("Cache-Control", "no-store"); 
     connection.setRequestProperty("Cache-Control", "no-cache"); 
     //  connection.setRequestProperty("If-None-Match", "no-store"); 
     connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
     connection.setRequestProperty("Accept", "application/xml"); 
     connection.setRequestProperty("charset", "utf-8"); 

    /* connection.setUseCaches(true); 
     connection.setDoOutput(true);*/ 


     Log.v("Response", " parameter = " + Parameters); 


     byte[] postData = Parameters.getBytes(StandardCharsets.UTF_8); 
     int postDataLength = postData.length; 
     connection.setRequestProperty("Content-Length", Integer.toString(postDataLength)); 
     OutputStream os = connection.getOutputStream(); 
     os.write(postData); 
     os.flush(); 

     // SystemClock.sleep(500); 

     int responseCode = connection.getResponseCode(); 
     Log.v("Response", "Sending 'POST' request to URL : " + url); 
     Log.v("Response", "Post parameters : " + Parameters); 
     Log.v("Response", "Response Code : " + responseCode); 
     Log.v("Response", "Message : " + connection.getResponseMessage()); 
     String result = connection.getHeaderField("Location"); 
     SettionKey = connection.getHeaderField("Location").substring(result.indexOf("v1.0/") + 5, result.length()); 
     Log.v("Response", "SessionKey = " + SettionKey); 
     connection.disconnect(); 
     // SystemClock.sleep(500); 
    } catch (IOException e) { 
     Log.v("Response", "Post Dead"); 
    } 

} 

public void get(String url) { 
    try { 
     Log.v("Response", "get"); 
     String url1 = url + "/" + SettionKey + "/?apiKey=" + apiKey; 
     URL url2 = new URL(url1); 

     HttpURLConnection connection = (HttpURLConnection) url2.openConnection(); 
     Log.v("Response", "url = " + url1); 

     connection.setRequestMethod("GET"); 
     connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded."); 
     connection.setRequestProperty("Accept", "application/xml"); 
     connection.setRequestProperty("Cache-Control", "no-cache"); 
     connection.setUseCaches(true); 
     connection.setDefaultUseCaches(true); 
     connection.setDoInput(true); 

     int responseCode = connection.getResponseCode(); 

     Log.v("Response", " " + connection.getHeaderFields()); 
     Log.v("Response", "code = " + responseCode); 
     Log.v("Response", connection.getResponseMessage()); 

     code = responseCode + connection.getResponseMessage(); 
     Flight.put("code", code); 
     InputStream is = null; 

     try { 
      is = new BufferedInputStream(connection.getInputStream()); 
      BufferedReader br = new BufferedReader(new InputStreamReader(is)); 

      setlist(br); 
      //Log.v("Response","result = "+inputLine.toString()); 
     } catch (IOException e) { 
      Log.v("Response", "read Dead.. "); 
     } 
     connection.disconnect(); 
    } catch (IOException e) { 
     Log.v("Response", "GET Dead "); 
    } 
} 

答えて

2

私は同じ問題があります。それから、私はそれを知ります:

フライトライブプライシングサービスは現在停止されています。私のソリューションは、devに関するデモAPIKEYを使用して、それらのサービスの再起動を待っているhere

かを確認することができます。

+0

あなたの答えをありがとう! – Park

1

あなたはHTTP-要求に対してレトロフィットライブラリを使用するため、私はお勧めします。 あなたのやり方よりも、より適切で快適で速いです。それはあなたのメソッドと対比して10-15文字のコードを使用します。あなたはここでそれを見つけることができます :

Retrofit IOGithub documentation

そして、ここでは、私は自分のアプリケーションで使用ScyScanner APIのいくつかの基本的な要求は、以下のとおりです。

Config.API_KEYがでいくつかの文字列である
@GET("reference/v1.0/locales?" + Config.API_KEY) 
Call<Locales> getLocales(@Header("Accept") String accept); 

私のAPIキーを保持するConfigクラス。このリクエストは、ロケールリストを取得するのに役立ちます。あなたが新しいものを取得するためにを試みるキーあなたのAPIを使用しての問題を持っている希望の場合

@GET("reference/v1.0/countries/{locale}?" + Config.API_KEY) Call<Markets> getMarketCountries(@Header("Accept") String accept, @Path("locale") String locale); 

は市場国

を取得します。それは私を助けた。幸運:)

+0

ありがとうございます!私はあなたのコードを勉強しようとします – Park

関連する問題