firebaseを使用してGoogleログインの認証を実装しようとしています。 私はthisチュートリアルに従っていました。java.lang.IllegalArgumentException:idTokenまたはaccessTokenを指定する必要があります
エラーログ:
java.lang.RuntimeException:失敗の送達結果 ResultInfo {ヌル=、= 1002要求、結果= -1、データ=テント{( 補足を有する)}}にアクティビティ {com.clabs.codefosterapp/com.clabs.codefosterapp.SplashActivity}: java.lang.IllegalArgumentException:idTokenまたは accessTokenを指定する必要があります。 android.app.ActivityThread.deliverResultsで
android.app.ActivityThread.access $ 1300 android.app.ActivityThread.handleSendResult(ActivityThread.java:3432)で(ActivityThread.java:3389) (ActivityThread.java :android.os.Looper.loop(ルーパーでandroid.os.Handler.dispatchMessage(Handler.java:102) で android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1244) で135) 。 java:136) android.app.ActivityThread.main(ActivityThread.java:5045) at java .lang.reflect.Method.invokeNative(ネイティブメソッド) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java java.lang.IllegalArgumentExceptionが:::によって引き起こさdalvik.system.NativeStart.main(ネイティブメソッド) で779)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595で ) idTokenを指定する必要があります またはアクセストークン。 com.google.firebase.auth.GoogleAuthCredential。(不明 出所) com.google.firebase.auth.GoogleAuthProvider.getCredentialで(不明 出所) com.clabs.codefosterapp.SplashActivity.firebaseAuthWithGoogle(SplashActivityでの 。ジャワ:102) com.clabs.codefosterapp.SplashActivity.onActivityResult(SplashActivity.java:91)android.app.ActivityThread.deliverResultsでandroid.app.Activity.dispatchActivityResult(Activity.java:5423) で(ActivityThreadで.java:3385) at android.app.Activit android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1244)アンドロイドで でandroid.app.ActivityThread.access $ 1300(ActivityThread.java:135) でyThread.handleSendResult(ActivityThread.java:3432) 。 os.Handler.dispatchMessage(Handler.java:102) (アンドロイド.os.Looper.loop(Looper.java:136) android.app.ActivityThread.main(ActivityThread.java:5045) at java.lang。メソッド.invokeNative(ネイティブメソッド) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit $ MethodAn dArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik。system.NativeStart.main(ネイティブメソッド)
はライン以下でクラッシュ
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
マイコード:
private void googleSignIn() {
Intent intent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(intent, SIGN_IN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
Toast.makeText(SplashActivity.this, "Oops! Something Went Wrong", Toast.LENGTH_SHORT).show();
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(SplashActivity.this, "Authentication Failed", Toast.LENGTH_SHORT).show();
}
}
});
}
依存関係を追加しましたか? https://firebase.google.com/docs/auth/android/google-signin –
はい、私はそれらを追加しました。 – Shubh
公式ドキュメントに記載されているすべての手順に従っていることを確認してからお知らせください。 –