Why is my program returning the google sign in 12500 error?

旧城冷巷雨未停 提交于 2020-05-16 03:33:26

问题


I am trying to get google sign in to work with my app. So far I think I have done everything correctly. I followed the google documentation on setting up the googlesigninclient, and can get the app to get to the sign in button, but when someone tries to sign in it returns the 12500 error (SIGN_IN_FAILED). I have the google api credentials set up correctly, and have it set up correctly in my debug.keystore, and I have the credentials.json file downloaded and in my app folder. I will post my code, does anyone know why it isn't working?

Thanks!

P.S. Just to head people off at the pass, I was testing it on my phone which definately has the latest version of google play services, so I don't think that is the problem

import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.api.Scope;
import com.google.android.gms.tasks.Task;

public class MainActivity extends AppCompatActivity {

    GoogleSignInClient mGoogleSignInClient;
    private static int RC_SIGN_IN = 100;
    private static final String TAG = "MainActivity";
    private SignInButton signInButton = null;
    private LinearLayout calendarLayout;
    private TextView email;
    private TextView name;
    private TextView getId;
    private TextView scopes;
    //private Scope scope = new Scope("https://www.googleapis.com/auth/calendar.events.readonly");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

        signInButton = findViewById(R.id.sign_in_button);
        signInButton.setSize(SignInButton.SIZE_STANDARD);
        signInButton.setColorScheme(SignInButton.COLOR_LIGHT);
    }

    @Override
    public void onStart() {
        super.onStart();

        // [START on_start_sign_in]
        // Check for existing Google Sign In account, if the user is already signed in
        // the GoogleSignInAccount will be non-null.
        GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
        updateUI(account);
        // [END on_start_sign_in]
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            // The Task returned from this call is always completed, no need to attach
            // a listener.
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            handleSignInResult(task);
        }
    }

    private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
        try {
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);

            // Signed in successfully, show authenticated UI.
            updateUI(account);
        } 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, "signInResult:failed code=" + e.getStatusCode());
            updateUI(null);
        }
    }

    public void updateUI(GoogleSignInAccount account) {
        if(account == null) {
            loadLogin();
        } else {
            loadCalendar(account);
        }
    }

    public void loadCalendar(GoogleSignInAccount account) {
        if(signInButton != null) {
            signInButton.setVisibility(View.INVISIBLE);
        }
        calendarLayout = findViewById(R.id.calendarLinearLayout);
        calendarLayout.setVisibility(View.VISIBLE);
        name = findViewById(R.id.name);
        name.setText(account.getDisplayName());
        email = findViewById(R.id.email);
        email.setText(account.getEmail());
        getId = findViewById(R.id.getId);
        getId.setText(account.getId());
        scopes = findViewById(R.id.scopes);
        scopes.setText(account.getRequestedScopes().toString());
    }

    private void loadLogin() {
        signInButton.setVisibility(View.VISIBLE);
        signInButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onSignInClicked();
            }
        });
    }

    private void onSignInClicked() {
        Intent signInIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }
}

Here are some of the logs that it put out into logcat:

10-30 07:19:09.987 1832-1832/com.example.aydus.cs356app D/dalvikvm: GC_FOR_ALLOC freed 275K, 11% free 3222K/3584K, paused 2ms, total 2ms
10-30 07:22:50.604 1832-1838/com.example.aydus.cs356app E/jdwp: REQ: UNSUPPORTED (cmd=6/3 dataLen=12 id=0x005baf)
10-30 07:22:57.934 1832-1832/com.example.aydus.cs356app W/EGL_emulation: eglSurfaceAttrib not implemented 3093 12436
10-30 07:26:50.601 1832-1832/com.example.aydus.cs356app W/MainActivity: signInResult:failed code=12500

回答1:


For me it was because I enabled Google Play App Signing, so you have to get the SHA1 from Release management -> App signing -> "App signing certificate" section




回答2:


Error code 10 is DEVELOPER_ERROR: https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes.html#DEVELOPER_ERROR

This almost certainly means you have not properly registered your SHA1 and Package Name in the Google API console: https://developers.google.com/identity/sign-in/android/start

If you are 100% sure that you have done this correctly, make sure that your GoogleSignInOptions are correct. In particular, make sure the web client ID (if you're using it) belongs to the same project where you registered your package name and SHA1.




回答3:


Simply update your Google Play Services to the latest version . If you are using AVD, Nexus 5 and 5X images support Google Play. Once the emulator is up and running, go to the Extended Controls Menu > Google Play then update.




回答4:


It may be a late answer, but helpful for some one. Enable Firebase for your project. Follow the steps to setup an android app. Make sure you have given support email. In my case that was the problem and giving a valid email, fix the problem.



来源:https://stackoverflow.com/questions/53058379/why-is-my-program-returning-the-google-sign-in-12500-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!