排球不响应API

时间:2019-04-17 07:11:00

标签: android android-volley

我正在尝试获取用户ID的Instagram API,但是当我尝试通过android的凌空库运行它时,出现此错误

  

E / Volley:[4914] BasicNetwork.performRequest:意外的响应代码   https://www.instagram.com/gmp009/?__a=1

为403

在我的浏览器中,该api可以很好地运行以JSON作为响应,但我不知道为什么我在截击中收到此错误

我尝试在互联网上搜索,但没有发现任何可以帮助我的东西。

 public void firstServiceCall(String url) {

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(
                Request.Method.GET, url, null,
                new Response.Listener<JSONObject>() {

              @Override
              public void onResponse(JSONObject response) {

                    try {
                            JSONObject user = response.getJSONObject("graphql");
                            JSONObject newUser = user.getJSONObject("user");

                            final String profilePicture = newUser.getString("id");
                            final String imageURL = newUser.getString("profile_pic_url");
                            Log.v("FUCK1", profilePicture.toString());

                            //finish();
                            //https://i.instagram.com/api/v1/users/30692469/info/    

                            String newURL = "https://i.instagram.com/api/v1/users/";
                            String NewURL3 = profilePicture;
                            String newURL2 = "/info/";

                            String REALURL = newURL + NewURL3 + newURL2;

                            secondServiceCall(profilePicture,REALURL);           
                        }

                        catch (JSONException e) {
                            e.printStackTrace();
                        }

                        //suppose the membershipid comes under main json with key "membershipid"
                        // on the response of first service ... call to the second service ... and continue so on... if required
                    }
                }, new Response.ErrorListener() {

            public void onErrorResponse(VolleyError error) {

                // As of f605da3 the following should work
                NetworkResponse response = error.networkResponse;
                if (error instanceof ServerError && response != null) {
                    try {
                        String res = new String(response.data,
                                HttpHeaderParser.parseCharset(response.headers, "utf-8"));
                        // Now you can use any deserializer to make sense of data
                        JSONObject obj = new JSONObject(res);
                    } catch (UnsupportedEncodingException e1) {
                        // Couldn't properly decode data to string
                        e1.printStackTrace();
                    } catch (JSONException e2) {
                        // returned data is not JSONObject?
                        e2.printStackTrace();
                    }
                }
            }
        });
        Volley.newRequestQueue(getApplicationContext()).add(jsonObjReq);
    }

0 个答案:

没有答案