Android Google Auth登录handleSignInResult:false

时间:2015-12-15 00:12:15

标签: android google-api google-plus google-signin google-authenticator

我正在开发我尝试使用Google登录的应用程序。但是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}}]

Developer Console中的一切都应该没问题。

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

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;

        }
    }

}

2 个答案:

答案 0 :(得分:4)

密钥库的SHA1指纹已损坏。你已经改变了〜/ .android / ?,重新安装了android studio?,你需要重新生成SHA1密钥。从https://console.developers.google.com/apis/credentials删除当前密钥api,并在〜/ .android / debug.keystore中使用新调试密钥存储的SHA1创建一个新密钥(默认密码为空)。

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

(function () {
    $(document).ajaxComplete(function (e, xhr, options) {
        if (xhr.status === 401 && xhr.statusText === "Session expired") {
            // Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event
            e.stopPropagation();
            location.href = xhr.getResponseHeader("Location");                
        }
    });
})();

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

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

答案 1 :(得分:2)

问题可能是因为您没有运行应用的签名版本 正如Sudhanshu Gaur在this post中指出的那样,首先尝试使用您用于create your json configuration file的相同密钥生成签名的apk。然后将其安装在您的设备上,看看它是否有效。原因是当您单击“运行”时,Android Studio不会对您的apk进行签名 我遇到了完全相同的问题,这个解决方案对我来说很好。