简体   繁体   English

在 Android 中使用 Volley 时出现意外响应代码 429?

[英]Unexpected response code 429 when using Volley in Android?

I'm able to fetch JSON information from a URL for a few minutes, however eventually it'll give me "Unexpected response code 429".我可以在几分钟内从 URL 获取 JSON 信息,但最终它会给我“意外响应代码 429”。 The link is from Steam, I'm wondering if this is a problem with Volley or Steam?链接来自 Steam,我想知道这是 Volley 还是 Steam 的问题? Here is my current implementation as it could be possible I'm missing something from my code.这是我当前的实现,因为我的代码中可能遗漏了一些东西。

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 response code means 429响应码表示

Too Many Requests

The user has sent too many requests in a given amount of time ("rate limiting").

Probably api you are trying to hit is limited to number of hits you can make in day or certain amount of time.您尝试点击的 api 可能仅限于您在一天或一定时间内可以进行的点击次数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM