Android - get facebook profile picture

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

    new AsyncTask() {
            @Override
            protected Bitmap doInBackground(String... params) {
                Bitmap bitmap = null;
                try {
                    String imageURL = "https://graph.facebook.com/" + mFbUserId +"/picture?width=150&width=150";
                    URL imageURI = new URL(imageURL);
                    bitmap = BitmapFactory.decodeStream(imageURI.openConnection().getInputStream());
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return bitmap;
            }
    
            @Override
            protected void onPostExecute(Bitmap bitmap) {
                super.onPostExecute(bitmap);
    
            }
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }
        }.execute();
    

提交回复
热议问题