Fernando Santiago Fernando Santiago - 1 month ago 16
Android Question

Get user profile image Android facebook SDK

How can i show the fecebook user profile image on Android?

I have been searching on the web and the answer seems to be to add the

https
to the
URL
, but i already set it and i can't get the image, instead of that, i get an interrogation mark:

enter image description here

Here is my code:

URL imageURL = null;
try {
imageURL = new URL("https://graph.facebook.com/" + userID + "/picture?width=" + width +"&height=" + width);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Bitmap bitmap = null;
try {
bitmap = getCroppedBitmap(BitmapFactory.decodeStream(imageURL.openConnection().getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}


A few months ago i could show the profile image with any problem, but now i got this... any idead?

Answer

For new SDK of facebook try this one :

loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            Log.v("LoginActivity", response.toString());

                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,picture");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException e) {
            e.printStackTrace();
        }
    });
Comments