Skip to content

Instantly share code, notes, and snippets.

@jampajeen
Created November 2, 2019 04:22
Show Gist options
  • Save jampajeen/e6ea1fa9583601921e2ef860d827370a to your computer and use it in GitHub Desktop.
Save jampajeen/e6ea1fa9583601921e2ef860d827370a to your computer and use it in GitHub Desktop.
FIrebase facebook login button (custom button)
Button btnFacebook = findViewById(R.id.btn_facebook);
Drawable leftDrawable = AppCompatResources.getDrawable(this, R.drawable.baseline_power_settings_new_black_18dp);
btnFacebook.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, null, null, null);
// Start Facebook integration
LoginManager fbLoginManager = com.facebook.login.LoginManager.getInstance();
mCallbackManager = CallbackManager.Factory.create();
fbLoginManager.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
// ...
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
// ...
}
});
btnFacebook.setOnClickListener(v -> fbLoginManager.logInWithReadPermissions(
this,
Arrays.asList("email", "public_profile", "user_birthday")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment