Android - get facebook profile picture

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

    Url seems OK.

    So problem is with your connection. Does URL.getContent() really return stream? Because if BitmapFactory gets null it also returns null.

    Try this:

    Bitmap bitmap = null;
    URL url = new URL(http://graph.facebook.com/"+userID+"/picture?type=large);
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    try {
       InputStream in = new BufferedInputStream(urlConnection.getInputStream());
       bitmap = BitmapFactory.decodeStream(in);
    }
    finally {
          urlConnection.disconnect();
    }
    

提交回复
热议问题