0

I am developing an app which has features of login via facebook and gmail. To load image from facebook and gmail, I am using volley.

For gmail, it is working fine but for fb it gives me an error :

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

I read this, but nothing happend

Code snippet:

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));

I read some stack overflow answer and according to this I also tried :

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

Here is my facebook photo url

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

Community
  • 1
  • 1
Tufan
  • 2,789
  • 4
  • 34
  • 52

2 Answers2

3

To solve redirect issue try this.You will get image url in image variable.

//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
                }
            }
        });

Volley throws 302 when the supplied URL redirects to another url. You provided graph url of facebook in Volley, when you open that url in browser it will redirect you to another url.

Kaushik
  • 6,150
  • 5
  • 39
  • 54
Arth Tilva
  • 2,496
  • 22
  • 40
1

Can you please try by adding "s" in your base URL like : https

In short if replace your URL http ---> https OR https ---> http

  • 1
    Please don't keep posting the same answer in multiple old questions. Flag as duplicate if you think they are. Another same answer https://stackoverflow.com/a/51435354/965146 – 4b0 Jul 20 '18 at 05:11