Android - get facebook profile picture

后端 未结 28 2318
花落未央
花落未央 2020-12-12 15:13

I don\'t know why, but I am always getting null when I try to get the profile picture of the user. Do I need to set some specific permissions to get access?

Below is

28条回答
  •  攒了一身酷
    2020-12-12 15:46

       public static Bitmap getFacebookProfilePicture(String userID)
                    throws SocketException, SocketTimeoutException,
                    MalformedURLException, IOException, Exception {
                String imageURL;
                Bitmap bitmap = null;
                imageURL = "http://graph.facebook.com/" + userID
                        + "/picture?type=large";
    
                 URL url1 = new URL(imageURL);
                    HttpURLConnection ucon1 = (HttpURLConnection) url1.openConnection();
                    ucon1.setInstanceFollowRedirects(false);
                    URL secondURL1 = new URL(ucon1.getHeaderField("Location"));
                InputStream in = (InputStream) new URL(imageURL).getContent();
                bitmap = BitmapFactory.decodeStream(in);
                return bitmap;
            }
    

    use this code.....

提交回复
热议问题