Volley 库给出了意外的响应代码 302

Volley Library gives unexpected response code 302

我正在开发一个具有通过 facebook 和 gmail 登录功能的应用程序。 要从 facebook 和 gmail 加载图像,我正在使用 volley。

对于 gmail,它工作正常,但对于 fb,它给我一个错误:

  E/Volley﹕ [380] BasicNetwork.performRequest: Unexpected response code 302 for http://graph.facebook.com/831173210283387/picture?type=large

我读了 this,但什么也没发生

代码片段:

ImageLoader.ImageCache imageCache = new BitmapLruCache()
ImageLoader imageLoader = new ImageLoader(Volley.newRequestQueue(mContext), imageCache);
imageLoader.get(pic_url, ImageLoader.getImageListener(holder.profile,
                R.drawable.ic_user, R.drawable.ic_user));

我阅读了一些堆栈溢出 answer 并且据此我也尝试了 :

HttpsURLConnection.setFollowRedirects(true);
pic_url.replace("https", "http");
Log.d("Photo url", pic_url);

这是我的脸书照片url

http://graph.facebook.com/831173210283387/picture?type=large

要解决重定向问题,请尝试 this.You 将在图像变量中获取图像 url。

//loginBtn = Facebook login button

loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {

            @Override
            public void onUserInfoFetched(GraphUser user) {
                // TODO Auto-generated method stub
                if (user != null) {

                    Session session = Session.getActiveSession();
                    if (session.isOpened()) {
                        Log.i("AccessToken", session.getAccessToken());

                    }

                    String image = "";
                    String id = user.getId();
                    try {
                        URL image_path = new URL("http://graph.facebook.com/"
                                + id + "/picture?type=large");
                        image = image_path + "";
                        Log.i("image::> ", image_path + "");

                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }
                } else {
                //ELSE PART
                }
            }
        });

当提供的 URL 重定向到另一个 url 时,Volley 抛出 302。您在 Volley 中提供了 facebook 的图表 url,当您在浏览器中打开该 url 时,它会将您重定向到另一个 url.

您能否尝试在您的基础 URL 中添加 "s",例如:https

简而言之,如果更换你的 URL HTTP ---> https 要么 https ---> http