[英]Google sign in doesn't respond
我有两个登录选项,普通登录和google登录。普通登录工作正常,但google登录不行。
我单击谷歌登录按钮,我可以看到帐户。所以我单击了帐户,但没有任何反应。此外,我在firebase上看不到用户数据。
我在模拟器或android studio上没有任何错误。我错过了一些东西,但是呢?
我正在按照本教程学习 Google登录方法。
更新错误日志
我终于找到了错误日志。问题是我每次都构建有签名的(release)apk,但是我在firebase上添加了调试SHA1代码。只是我在模拟器上运行了调试模式。
EXCEPTION: main
Process: com.app.surebettips, PID: 3806
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.app.surebettips/com.app.surebettips.Login}: java.lang.IllegalArgumentException: Must specify an idToken or an accessToken.
at android.app.ActivityThread.deliverResults(ActivityThread.java:3574)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3617)
at android.app.ActivityThread.access$1300(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException: Must specify an idToken or an accessToken.
at com.google.firebase.auth.GoogleAuthCredential.<init>(Unknown Source)
at com.google.firebase.auth.GoogleAuthProvider.getCredential(Unknown Source)
at
/****HERE***/
com.app.surebettips.Login.firebaseAuthWithGoogle(Login.java:467)
at com.app.surebettips.Login.onActivityResult(Login.java:376)
/****HERE***/
at android.app.Activity.dispatchActivityResult(Activity.java:6192)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3570)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3617)
at android.app.ActivityThread.access$1300(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
09-06 09:49:09.566 3806-3806/com.app.surebettips I/Process: Sending signal. PID: 3806 SIG: 9
线:467
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
线:376
firebaseAuthWithGoogle(account);
Google登录错误的响应通常是由于SHA指纹不正确,或者根本没有在Google API控制台中定义。 在视频中,作者使用了一个旧教程。 这是当前版本: https : //firebase.google.com/docs/auth/android/google-signin ,它包含集成教程中标准Google Sing的链接: https : //developers.google.com/identity / sign-in / android / sign-in
这是必需的,因为在本教程中还有另一个链接来配置Google API控制台: https : //developers.google.com/identity/sign-in/android/start-integrating通常需要在其中配置当前API项目的位置如果您更改了它或在API控制台中创建了其他项目,则它的名称为Google Play Android Developer或其他名称。
您需要在此处设置SHA-1指纹和软件包名称。 如果您将其设置为正确的项目(如果有多个项目),则Google登录将正常运行。
另外,您正在使用GoogleSignIn Client,因此在创建Sing In Intent时也必须使用它
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
因此,请从Google查看本教程并按照文档所述实施本教程,一切正常。 https://developers.google.com/identity/sign-in/android/start-integrating
在onActivityResult回调内部,执行以下操作:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
try {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
GoogleSignInAccount account = task.getResult(ApiException.class);
// User is logged in on google platform
Log.v(TAG, "Account token:" + account.getIdToken()); //NON-NLS
// Signed in successfully, show authenticated UI.
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w(TAG, "Google sign in failed", e); //NON-NLS
String messageToDisplay = "Authentication failed.";
switch (e.getStatusCode()) {
case CommonStatusCodes.API_NOT_CONNECTED: //17
messageToDisplay += "The client attempted to clearPreferences a method from an API that failed to connect.";
break;
case CommonStatusCodes.DEVELOPER_ERROR: //10
messageToDisplay += "The application is misconfigured.";
break;
case CommonStatusCodes.ERROR: //13
messageToDisplay += "The operation failed with no more detailed information.";
break;
case CommonStatusCodes.INTERNAL_ERROR: //8
messageToDisplay += "An internal error occurred.";
break;
case CommonStatusCodes.INVALID_ACCOUNT: //8
messageToDisplay += "Invalid account name specified.";
break;
case CommonStatusCodes.SIGN_IN_REQUIRED: //8
messageToDisplay += "Please Sign In to continue.";
break;
}
}
}
}
这样,您就可以了解为什么登录无法正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.