Android - get facebook profile picture

后端 未结 28 2322
花落未央
花落未央 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:50

    This should solve it. but be sure to access setfollowredirects statically i.e HttpURLConnection.setFollowRedirects(HttpURLConnection.getFollowRedirects());

    url = new URL("https://graph.facebook.com/ID/picture?type=small");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();                                           HttpURLConnection.setFollowRedirects(HttpURLConnection.getFollowRedirects());
    connection.setDoInput(true);
    connection.connect();
    input = connection.getInputStream();
    
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(input, null, options);
    
    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, 300, 300);
    
     // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    options.inPreferredConfig = Config.RGB_565;
    myBitmap= BitmapFactory.decodeStream(input, null, options);
    

    or

    url = new URL("https://graph.facebook.com/ID/picture?type=small");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();                                                HttpURLConnection.setFollowRedirects(HttpURLConnection.getFollowRedirects());
    connection.setDoInput(true);
    connection.connect();
    input = connection.getInputStream();
    myBitmap= BitmapFactory.decodeStream(input);
    

    Hope this helps

提交回复
热议问题