私はStackoverflowを使用して、提案された回答を試みましたが、どれも動作していません。私はfirebeaseとgoogleでユーザーを認証しようとしていますが、私のコードは正常に動作しています。しかし、この方法では、私はいつもトーストメッセージ認証が失敗した取得しています:Google Sign-in認証が機能しません
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
auth.signInWithCredential(credential)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
私は私のGoogle-services.jsonと私のGoogleのAPIの資格情報を使用して行うための何かを信じています。誰かがこの問題を解決するための明確なステップを私に教えてくれるかどうか疑問に思っていました。これは私がサインインプロセスを動作させるために試みたものです。
- 私のアプリケーションをfirebaseでリンクし、JSONをプロジェクトに正しく追加しました。
- すべてのビルドGradleの依存関係Googleはサインインfirebase認証]タブから
- は(here)APIの資格情報のウェブサイトをGoogleに行き、コピーされたとのstrings.xmlにそれを格納し、私のプロジェクト内
- ウェント可
- を追加しましたバック資格情報ページへとAndroid用の別の認証トークンを作成し、SHA1のキーを取得するために、端末にこれを入力した:
ストア-list -vrt -alias androiddebugkey -keystore〜/ .android /デバッグを。アンドロイド
としてパスワードを使用して
アンドロイド認証トークンを作成するときに、私は、このキーを入力します。私がされている
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
Toast.makeText(LoginActivity.this, "Passed google login", Toast.LENGTH_SHORT).show();
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
}
}
}
/*****************************************************************************************************/
/*get an ID token from the GoogleSignInAccount object, exchange it for a Firebase credential,
*and authenticate with Firebase using the Firebase credential
*/
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
auth.signInWithCredential(credential)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
私もリスナーと一緒に、あまりにものonCreate
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_id))
.requestEmail()
.build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
と内側に私のサインインクラスの内部でこのすべてをこのコードのすべてを持っているとONSTARTと停止方法非常に長い時間のためにこれに立ち往生し、どんな助けも大歓迎です。私は自分の問題が何であるかについてはっきりしていないが、私はそれだけを推測している。さらに詳しい情報が必要な場合は、私に知らせてください。私はこの投稿を更新します。
ありがとう
ここでは、使用しているファイルが正しい指紋を持っているかどうかを確認することができます。 –