1

I am integrating Facebook sdk in my android app very first time... I am having some issues with getting my facebook profile picture into my app.

Here is onSuccess Callback method:

public void onSuccess(LoginResult loginResult) {
            Profile profile = Profile.getCurrentProfile();
            if(profile != null) {
                Log.v("Logged In Message", profile.getName());
                imageView.setImageURI(profile.getProfilePictureUri(50, 50));
            }
        }

Issue is that I am getting correct name but not profile Image...

Any Help would be appreciated

Ali Mehdi
  • 884
  • 1
  • 11
  • 33

2 Answers2

1

You don't need to have profile image. You can get user profile image by it's unique id call uid like as follow

http://graph.facebook.com/451985168296158/picture?width=150&height=150
Nooruddin Lakhani
  • 7,507
  • 2
  • 19
  • 39
  • I have got this error Unable to decode stream: java.io.FileNotFoundException: /http:/graph.facebook.com/1503273343323126/picture?width=150&height=150: open failed: ENOENT (No such file or directory) – Ali Mehdi Sep 28 '15 at 12:13
  • You can download image into bitmap .. http://stackoverflow.com/questions/8992964/android-load-from-url-to-bitmap – Nooruddin Lakhani Sep 28 '15 at 12:20
1

code sample

loginManager.logInWithReadPermissions(SocialPluginMainActivity.this, permissionNeeds);
        loginManager.registerCallback(fbCallbackManager, 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) {
                                // Application code
                                Log.v("LoginActivity", response.toString());
                                try {
                                    fbUserId = object.getString("id");
                                    fbUserName = object.getString("name");
                                    fbEmail = object.getString("email");
                                    fbGender = object.getString("gender");
                                    fbDob = object.getString("birthday");
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                Glide.with(SocialPluginMainActivity.this).load("http://graph.facebook.com/" +fbUserId +"/picture?type=large").into(profilePicImgView);
                            }
                        });
                Bundle parameters = new Bundle();
                parameters.putString("fields", "id,name,email,gender,birthday");
                request.setParameters(parameters);
                request.executeAsync();
            }

            @Override
            public void onCancel() {

            }

            @Override
            public void onError(FacebookException e) {

            }
        });
Kaushik
  • 6,150
  • 5
  • 39
  • 54