我能够在几分钟内从 URL 获取 JSON 信息,但最终它会给我“意外的响应代码 429”。该链接来自 Steam,我想知道这是 Volley 还是 Steam 的问题?这是我当前的实现,因为我的代码中可能遗漏了一些东西。
RequestQueue queue = Volley.newRequestQueue(this);
// Request a string response from the provided URL.
JsonObjectRequest stringRequest = new JsonObjectRequest(Request.Method.GET, retrievalURL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
int indexOfWear = listOfWears.indexOf(wear);
Map<String, String> itemInList = listWearsAndPrices.get(indexOfWear);
if (response.getBoolean("success")) {
itemInList.put("Price", response.getString("lowest_price"));
} else {
// If price is not possible
itemInList.put("Price", "Item Unavailable");
Log.e("tag", "Item unavailable unreached");
}
// Update view
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
/**
* TODO
* CHECK FOR INTERNET CONNECTION
*/
int indexOfWear = listOfWears.indexOf(wear);
Map<String, String> itemInList = listWearsAndPrices.get(indexOfWear);
itemInList.put("Price", "Item Unavailable");
adapter.notifyDataSetChanged();
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
最佳答案
429响应码表示
Too Many Requests
The user has sent too many requests in a given amount of time ("rate limiting").
您尝试点击的 api 可能会限制您在一天或特定时间内可以点击的次数。
关于java - 在 Android 中使用 Volley 时意外的响应代码 429?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36977284/