1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| this.facebookLoginButton.setReadPermissions("email", "public_profile"); this.facebookLoginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { LogUtils.d("facebook:onSuccess:" + loginResult); handleFacebookAccessToken(loginResult.getAccessToken()); } }
private void handleFacebookAccessToken(final AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token.getUserId()); // [START_EXCLUDE silent] loadingProgressDialog = UIHelper.showLoading(mActivity, false, loadingProgressDialog);
// [END_EXCLUDE]
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); FirebaseAuth.getInstance().signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information LogUtils.e("signInWithCredential:success"); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
LogUtils.e(user.getEmail()); LogUtils.e(user.getPhoneNumber()); LogUtils.e(user.getUid()); LogUtils.e(user.getPhotoUrl().toString()); LogUtils.e(user.getDisplayName());
String photoUrl = user.getPhotoUrl().toString() ; if (!TextUtils.isEmpty(photoUrl)){ photoUrl = photoUrl + "?width=300&height=300"; }
IUserManager userManager = new IUserManager(-1, user.getEmail(), user.getDisplayName(), photoUrl, token.getUserId(), Common.LoginPlatform.facebookLoginPlatform); userManager.token = token.getToken();
thirdPlatFormLogin(userManager); LogUtils.e(user.toString());
// updateUI(user); } else { // If sign in fails, display a message to the user. UIHelper.dismissLoading(loadingProgressDialog);
String hint = UIUtils.getString(R.string.ActivityLogin_Authentication_Failed, Common.LoginPlatform.facebookLoginPlatform); ToastUtils.showShort(hint); Log.w(TAG, "signInWithCredential:failure", task.getException()); // Toast.makeText(mActivity, "Authentication failed.", // Toast.LENGTH_SHORT).show(); // updateUI(null); }
// [START_EXCLUDE] // hideProgressDialog(); // [END_EXCLUDE] } }); }
|