I need to get tokenId with google login and everything works if I use my google developer account, but as soon as I switch to another developer account, then:
Error 12501 authenticating I think my implementation of GCM and Google button can somehow be connected?
I hope I didn’t explain in a very confusing way, if you need to add something - ask!
thank
Edit
GCM Initialization
public class RegisterGCM { private GoogleCloudMessaging gcm; private Context context; private Activity activity; private SharedPreferences sharedPreferences; private int versionCode = 0; private String versionName; private static final String PROPERTY_REG_ID = "registration_id"; private static final String PROPERTY_APP_VERSION = "appVersion"; private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000; /** * Substitute you own sender ID here. This is the project number you got * from the API Console, as described in "Getting Started." */ private String SENDER_ID; private String registrationId; public RegisterGCM(Context context, Activity activity, SharedPreferences sharedPreferences, int versionCode, String versionName, String SENDER_ID) { this.activity = activity; this.context = context; this.sharedPreferences = sharedPreferences; this.versionCode = versionCode; this.versionName = versionName; this.SENDER_ID = SENDER_ID; checkServices(); } private void checkServices() { // Check device for Play Services APK. If check succeeds, proceed with GCM registration. if (checkPlayServices()) { gcm = GoogleCloudMessaging.getInstance(context); registrationId = getRegistrationId(context); if (registrationId.isEmpty()) { registerInBackground(); } } else { Logger.log(RegisterGCM.class, "No valid Google Play Services APK found.", Logger.ERROR); } } /** * Check the device to make sure it has the Google Play Services APK. If * it doesn't, display a dialog that allows users to download the APK from * the Google Play Store or enable it in the device's system settings. */ public boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, activity, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { Logger.log(RegisterGCM.class, "This device is not supported.", Logger.ERROR); } return false; } return true; } /** * Stores the registration ID and the app versionCode in the application's * {@code SharedPreferences}. * * @param context application's context. * @param regId registration ID */ private void storeRegistrationId(Context context, String regId) { final SharedPreferences prefs = sharedPreferences; int appVersion = UtilClass.getAppVersion(context); SharedPreferences.Editor editor = prefs.edit(); editor.putString(PROPERTY_REG_ID, regId); editor.putInt(PROPERTY_APP_VERSION, appVersion); editor.apply(); } /** * Gets the current registration ID for application on GCM service, if there is one. * <p/> * If result is empty, the app needs to register. * * @return registration ID, or empty string if there is no existing * registration ID. */ private String getRegistrationId(Context context) { final SharedPreferences prefs = sharedPreferences; String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.isEmpty()) { Logger.log(RegisterGCM.class, "Registration not found.", Logger.ERROR); return ""; } // Check if app was updated; if so, it must clear the registration ID // since the existing regID is not guaranteed to work with the new // app version. int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int currentVersion = UtilClass.getAppVersion(context); if (registeredVersion != currentVersion) { Logger.log(RegisterGCM.class, "App version changed.", Logger.ERROR); return ""; } return registrationId; } /** * Registers the application with GCM servers asynchronously. * <p/> * Stores the registration ID and the app versionCode in the application's * shared preferences. */ private void registerInBackground() { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { if (gcm == null) { gcm = GoogleCloudMessaging.getInstance(context); } registrationId = gcm.register(SENDER_ID); // You should send the registration ID to your server over HTTP, so it // can use GCM/HTTP or CCS to send messages to your app. WrapperUserRecorder wrapperUserRecorder = new WrapperUserRecorder(SENDER_ID, registrationId, versionCode, versionName); new UserRecorder(wrapperUserRecorder, context).sendRegistrationIdToBackend(); // Persist the regID - no need to register again. saveIDSendFlag(States.WAS_SEND); storeRegistrationId(context, registrationId); } catch (IOException ex) { // If there is an error, don't just keep trying to register. // Require the user to click a button again, or perform // exponential back-off. Logger.log(RegisterGCM.class, "Expiry connecting to the server is out", Logger.ERROR); saveIDSendFlag(States.WAS_NOT_SEND); } return null; } }.execute(); } private void saveIDSendFlag(boolean flag) { SharedPrefUtil.saveIDSendFlag(context, flag); } /** * Initialize and register app in GCM **/ public static RegisterGCM initGCM(Context context, Activity activity) { /** * Substitute you own sender ID here. This is the project number you got * from the API Console, as described in "Getting Started." */ String SENDER_ID = context.getResources().getString(R.string.SENDER_ID); SharedPreferences sharedPreferences = context.getSharedPreferences( RegisterGCM.class.getSimpleName(), Context.MODE_PRIVATE); int versionCode = 0; String versionName = null; try { versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return new RegisterGCM(context, activity, sharedPreferences, versionCode, versionName, SENDER_ID); } } Initiating Google LogIn
public class GoogleImplementation { private static Context context; private ActivityAuthorization authorizationActivity; private GoogleApiClient mGoogleApiClient; private String tokenID; public GoogleImplementation(Context context, ActivityAuthorization authorizationActivity) { GoogleImplementation.context = context; this.authorizationActivity = authorizationActivity; } public void initGoogleLogIn() { GoogleSignInOptions gso = getGoogleSignInOptions(); mGoogleApiClient = getGoogleApiClient(gso); SignInButton btnSignIn = (SignInButton) authorizationActivity.findViewById(R.id.btn_sign_in); btnSignIn.setOnClickListener(listener); } @NonNull private GoogleSignInOptions getGoogleSignInOptions() { return new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(context.getResources().getString(R.string.server_id)) .build(); } @NonNull private GoogleApiClient getGoogleApiClient(GoogleSignInOptions gso) { return new GoogleApiClient.Builder(context) .enableAutoManage(authorizationActivity, listenerConnection) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); } GoogleApiClient.OnConnectionFailedListener listenerConnection = new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Logger.log(GoogleImplementation.class, "user have tried to logIn with Google but onConnectionFailed", Logger.ERROR); } }; View.OnClickListener listener = new View.OnClickListener(){ @Override public void onClick(View view) { if (!UtilClass.isNetworkConnection(context)) { UtilClass.showDialog(authorizationActivity.getFragmentManager(), new CallBackDialog()); } Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); authorizationActivity.startActivityForResult(signInIntent, States.GOOGLE_SIGNIN); } }; public void getUserGoogleData(GoogleSignInResult result, GoogleSignInAccount acct) { String name = getName(acct); tokenID = getTokenId(result); String personPhotoUrl = getPersonPhotoUrl(acct).toString(); String personEmail = acct.getEmail(); String personID = acct.getId(); AuthorisationMaker.setPersonEmail(personEmail); AuthorisationMaker.setPersonId(personID); Logger.log(ActivityAuthorization.class, "name : " + name + " ID : " + tokenID + " personPhotoUrl " + personPhotoUrl + " personEmail : " + personEmail, Logger.ERROR); } public String getTokenID() { return tokenID; } private Uri getPersonPhotoUrl(GoogleSignInAccount acct) { return acct.getPhotoUrl(); } private String getTokenId(GoogleSignInResult result) { String tokenId = null; GoogleSignInAccount googleSignInAccount = result.getSignInAccount(); if (googleSignInAccount != null) { tokenId = googleSignInAccount.getIdToken(); } return tokenId; } @Nullable private String getName(GoogleSignInAccount acct) { String name = null; if (acct != null) { name = acct.getDisplayName(); } return name; } } The configuration file generated by this link
That's what's in the file
{ "project_info": { "project_number": "2693226048", "project_id": "ntzfr-17" }, "client": [ { "client_info": { "mobilesdk_app_id": "1:2693224268:android:f802e670e6118171", "android_client_info": { "package_name": "com.fitingroom.newtimzone" } }, "oauth_client": [ { "client_id": "2693224248- o45crnrc6hnb200lhdam1uq95d72isi0.apps.googleusercontent.com", "client_type": 1, "android_info": { "package_name": "com.fitingroom.newtiezone", "certificate_hash": "5F6293FCD8F8FD026FF3B40F73CC1E5E7B239F" } }, { "client_id": "2693226048-c2t8ndm60ak6u6n4rc0cjq8q3s8ltd.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { "current_key": "ACrhi0BnxTnNRBsYyH451nZ7DSYaJc" } ], "services": { "analytics_service": { "status": 1 }, "appinvite_service": { "status": 1, "other_platform_oauth_client": [] }, "ads_service": { "status": 1 } } } ], "configuration_version": "1" }