Emre Erol
Emre Erol

Reputation: 460

How to get facebook user info in android?

I am using this code for access user information in my app. But nothing change.. Accualy when i debug the code, login.registerCallback and below never called. No error and nothing change.

Where is my fault ?

   @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            FacebookSdk.sdkInitialize(getApplicationContext());
            callbackManager = CallbackManager.Factory.create();
            setContentView(R.layout.activity_main);

            loginButton = (LoginButton) findViewById(R.id.login_button);
            loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    Profile profile = Profile.getCurrentProfile();
                    String userID = loginResult.getAccessToken().getUserId();
                    String profileImgUrl = "https://graph.facebook.com/" + userID + "/picture?type=large";
                    tv = (TextView) findViewById(R.id.textView);
                    tv.setText(profile.getName());

                    try {
                        bitmap = getBitmapFromUrl(profileImgUrl);
                        iv = (ImageView) findViewById(R.id.imageView);
                        iv.setImageBitmap(bitmap);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }

Upvotes: 0

Views: 1424

Answers (1)

Mehdi Sakout
Mehdi Sakout

Reputation: 783

it's because you forgot to add the following block in your activity :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

Upvotes: 2

Related Questions