4

I retrieved details like userID, email, name, etc but I want to set user profile picture in my imageview.
How can it be done?

loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

    String id;
    String name;
    String email;
    String gender;

    @Override
    public void onSuccess(LoginResult loginResult) {

        System.out.println("onSuccess");
        GraphRequest request = GraphRequest.newMeRequest
                (loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                        // Application code
                        Log.v("LoginActivity", response.toString());
                        //System.out.println("Check: " + response.toString());
                        try {
                            id = object.getString("id");
                            // picture= object.getJSONObject("picture").getJSONObject("data").getString("url");
                            name = object.getString("name");
                            email = object.getString("email");
                            gender = object.getString("gender");
                            // birthday = object.getString("birthday");
                            // String location = object.getString("user_location");

                            Log.v("id", id);
                            Log.v("name", name);
                            Log.v("email", email);
                            Log.v("gender", gender);

                            SharedPreferences.Editor e = mSharedPreferences.edit();
                            e.putBoolean(PREF_KEY_FACEBOOK_LOGIN, true);
                            e.putString("id", id);
                            e.putString("name", name);
                            e.putString("email", email);
                            e.putString("gender", gender);
                            e.commit();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    // Toast.makeText(getApplicationContext(), id + "\n"  + name + 
                    // "\n" + email + "\n" + gender, Toast.LENGTH_LONG).show();
                }


    });

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

I am using v2.3 version and login button is a predefined button of facebook library please help me or guide me thanks in advance.

almightyGOSU
  • 3,731
  • 6
  • 31
  • 41
  • refer to the post http://stackoverflow.com/questions/3012905/how-can-i-display-the-users-profile-pic-using-the-facebook-graph-api – YesR Jul 08 '15 at 05:25

2 Answers2

4

finally i got answer i use this code

       public static Bitmap getFacebookProfilePicture(String userID) throws IOException {
                URL imageURL = new URL("https://graph.facebook.com/" + userID + "/picture?type=large");
                Bitmap bitmap = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());

                return bitmap;
            }

   // on createView method 

            try {
                Bitmap mBitmap = getFacebookProfilePicture(id);
                imageView.setImageBitmap(mBitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }
2

just use fb id to get profile picture of the user.

try this one...

String fbImg = "http://graph.facebook.com/"+retrived_user_id+"/picture";

now you can use this 'fbImg' string to load profile pic.

khaleel_jageer
  • 1,404
  • 4
  • 16
  • 37