在android studio中Google登录失败[关闭]时出错

问题描述 投票:-5回答:1
通过我已连接到

firebase和synced按钮登录时,成功完成错误

我们在Android应用中添加Google登录所必须采取的步骤

登录时出错。

android firebase android-studio authentication google-login
1个回答
-2
投票
<com.google.android.gms.common.SignInButton android:id="@+id/sign_in_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginStart="9dp" android:layout_marginBottom="109dp" />

然后在主要活动中从GoogleSignInClient获取实例通过此代码

    public GoogleSignInClient mGoogleSignInClient;

然后在onCreate方法中初始化此对象

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

然后使用XML的onClick发送请求以使用“使用Gmail登录”,>

    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, 1);

最终覆盖OnActivityResult并通过以下方式获取userData:>

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

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == 1) {
        // The Task returned from this call is always completed, no need to attach
        // a listener.
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.