Android Google Auth登录句柄SignInResult:false



我正在开发尝试使用谷歌登录的应用程序。但是getExtrasdata总是返回null。

这是我从日志中得到的:

getSignInIntent = { act=com.google.android.gms.auth.GOOGLE_SIGN_IN cmp=com.rbsoftware.pfm.personalfinancemanager/com.google.android.gms.auth.api.signin.internal.SignInHubActivity (has extras) }
mGoogleApiClient=com.google.android.gms.internal.zzmg@1f595441
handleSignInResult:false
result=com.google.android.gms.auth.api.signin.GoogleSignInResult@7d8c188
data=Intent { (has extras) }
getExtrasdata=Bundle[{googleSignInStatus=Status{statusCode=INTERNAL_ERROR, resolution=null}}]

开发人员控制台中的一切都应该正常。

你能帮我解决这个问题吗?

package com.rbsoftware.pfm.personalfinancemanager;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.OptionalPendingResult;
import com.google.android.gms.common.api.ResultCallback;

public class LoginActivity extends AppCompatActivity implements
        GoogleApiClient.OnConnectionFailedListener,
        View.OnClickListener {
    private static final String TAG = "SignInActivity";
    private static final int RC_SIGN_IN = 9001;
    public GoogleApiClient mGoogleApiClient;
    private ProgressDialog mProgressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        // Button listeners
        findViewById(R.id.sign_in_button).setOnClickListener(this);

        // [START configure_signin]
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        // [END configure_signin]
        // [START build_client]
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();
        // [END build_client]
        // [Button]
        SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
        signInButton.setSize(SignInButton.SIZE_WIDE);
        signInButton.setScopes(gso.getScopeArray());
    }
    @Override
    public void onStart() {
        super.onStart();
        OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
        if (opr.isDone()) {
            Log.d(TAG, "Got cached sign-in");
            GoogleSignInResult result = opr.get();
            handleSignInResult(result);
        } else {
            opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
                @Override
                public void onResult(GoogleSignInResult googleSignInResult) {
                    handleSignInResult(googleSignInResult);
                }
            });
        }
    }
    // [START onActivityResult]
    @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);
            handleSignInResult(result);
        }
    }
    // [END onActivityResult]
    // [START handleSignInResult]
    private void handleSignInResult(GoogleSignInResult result) {
        Log.d(TAG, "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();
            Intent intent = new Intent(this, MainActivity.class);
            intent.putExtra("name", acct.getDisplayName());
            intent.putExtra("id", acct.getId());
            intent.putExtra("email", acct.getEmail());
            intent.putExtra("photoURL", acct.getPhotoUrl());
            Log.d("USER Pic", acct.getPhotoUrl()+"");
            startActivity(intent);
            finish();
                   } else {
        }
    }
    // [END handleSignInResult]
    // [START signIn]
    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }
    // [END signIn]

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.d(TAG, "onConnectionFailed:" + connectionResult);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sign_in_button:
                signIn();
                break;
        }
    }
}

密钥库的SHA1指纹已损坏。你已经更改了~/.android/?,是否重新安装了android工作室?,您需要重新生成SHA1密钥。从中删除当前密钥apihttps://console.developers.google.com/apis/credentials并在~/.android/debug.keystore中使用新调试密钥存储的SHA1制作新密钥(默认密码为空)。

看看这个:https://www.numetriclabz.com/android-google-integration-and-login-tutorial/

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v

将SHA1粘贴到用于调试实例的新密钥api中。

记住:您需要生产密钥库的其他指纹。

问题可能是因为您没有运行应用程序的签名版本
正如Sudhanshu Gaur在这篇文章中指出的那样,首先尝试使用创建json配置文件时使用的相同密钥生成一个签名的apk。然后把它安装在你的设备上,看看它是否工作。原因是当你点击"运行"时,安卓工作室不会签署你的apk
我陷入了完全相同的问题,这个修复对我来说很好。

相关内容

  • 没有找到相关文章

最新更新