Skyscanner Travel API / 使用私人 Apikey / return 429
Skyscanner Travel API / use private Apikey / return 429
我想在我的 Android 应用程序中使用 Travel Api
第一个测试工具演示 API 密钥 (prtl6749387986743898559646983194)
returns 200,成功创建会话并轮询会话
但是,在使用仪表板私钥 API 时,它 return 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 ");
}
}
首先,我建议您使用 Retrofit 库 进行 HTTP 请求。
它比你的方式更合适、更舒适、更快捷。它将使用 10-15 串代码与您的方法进行对比。
您可以在这里找到它:
Retrofit IO 和
Github documentation
下面是我在应用程序中使用的 ScyScanner API 的一些基本请求:
@GET("reference/v1.0/locales?" + Config.API_KEY)
Call<Locales> getLocales(@Header("Accept") String accept);
其中 Config.API_KEY 是 Config class 中的某个字符串,其中包含我的 API 密钥。此请求可以帮助您获取语言环境列表。
@GET("reference/v1.0/countries/{locale}?" + Config.API_KEY)
Call<Markets> getMarketCountries(@Header("Accept") String accept, @Path("locale") String locale);
获取市场国家
如果您在使用 API 密钥时遇到任何问题,请尝试 获取新密钥。 它对我有帮助。祝你好运:)
我遇到了同样的问题。然后我发现:
Flights Live Pricing service is currently suspended.
您可以在here
查看
我的解决方案是使用 demo apiKey for dev,并等待他们的服务重新启动。
我想在我的 Android 应用程序中使用 Travel Api
第一个测试工具演示 API 密钥 (prtl6749387986743898559646983194) returns 200,成功创建会话并轮询会话
但是,在使用仪表板私钥 API 时,它 return 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 ");
}
}
首先,我建议您使用 Retrofit 库 进行 HTTP 请求。 它比你的方式更合适、更舒适、更快捷。它将使用 10-15 串代码与您的方法进行对比。 您可以在这里找到它:
Retrofit IO 和 Github documentation
下面是我在应用程序中使用的 ScyScanner API 的一些基本请求:
@GET("reference/v1.0/locales?" + Config.API_KEY)
Call<Locales> getLocales(@Header("Accept") String accept);
其中 Config.API_KEY 是 Config class 中的某个字符串,其中包含我的 API 密钥。此请求可以帮助您获取语言环境列表。
@GET("reference/v1.0/countries/{locale}?" + Config.API_KEY)
Call<Markets> getMarketCountries(@Header("Accept") String accept, @Path("locale") String locale);
获取市场国家
如果您在使用 API 密钥时遇到任何问题,请尝试 获取新密钥。 它对我有帮助。祝你好运:)
我遇到了同样的问题。然后我发现:
Flights Live Pricing service is currently suspended.
您可以在here
查看我的解决方案是使用 demo apiKey for dev,并等待他们的服务重新启动。