1
我能夠從URL獲取JSON信息幾分鐘,但最終它會給我「意外的響應代碼429」。鏈接來自Steam,我想知道這是Volley還是Steam的問題?這是我目前的實現,因爲它可能會從我的代碼中丟失一些東西。在Android中使用Volley時出現意外的響應代碼429?
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);
您是否在點擊服務前檢查了互聯網連接? –