Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – FirebaseException: An internal error has occurred. [ API key expired. Please renew the API key. ]

Posted on November 11, 2022 By

Solution 1 :

Although it’s good that API Keys are set to expire, I hadn’t realized that Firebase sets the API Keys that it creates to expire (yearly) until I investigated after reading your question.

If you haven’t seen this, please see … managing API keys for Firebase

You can view API keys for a project two ways:

  1. Firebase Console, select your Project, click the ‘gear’ icon next to “Project Overview” and then “Project Settings”.
  2. Cloud Console, select your Project, then “APIs & Services” and then choose “Credentials”.

The documentation doesn’t appear to cover the renewal process.

I suspect (!?) that you can use e.g. Cloud Console, find the correct API Key and click “REGENERATE KEY”.

Then you will need to revise all occurrences of this API Key in your distributed (!) code.

For example, I’m only using Web clients and I have:

const firebaseConfig = {
  apiKey: "[[HERE]]",
  authDomain: "...",
  projectId: "...",
  storageBucket: "..",
  messagingSenderId: "...",
  appId: "..."
};

I assume (!?) there’s an equivalent config for Android apps.

Solution 2 :

Glad to inform you that the issue has been resolved. The troublemaker was an old version of the “google-services.json” in the “Build” folder. Removing and replacing it with the updated version of “google-services.json” worked like a charm.

Problem :

I am developing an Android app and trying to implement a Google sign-in functionality. The authentication info that it’s supposed to produce, is stored in my Firebase database. It seemed to have worked until recently.
I have been trying to resolve this frustrating exception in many ways:

  • I regenerated an API key on GCP, redownloaded google-services.json and rebuilt the project.
  • I noticed that the API key specified in the values.xml file (this file is stored in appbuildgeneratedresgoogle-servicesdebugvalues) is outdated. Therefore, I tried to modify the fields “google_api_key” and “google_crash_reporting_api_key”, as well as delete the file itself. The outdated data appears as soon as I rebuild the project.
  • I made sure that the SHA-1 is specified in the Firebase console
  • I set the API key’s restrictions using GCP
READ  [FIXED] android - Dynamically add choicechip on flutter
Powered by Inline Related Posts

Google sign-in code:

   private void loginUserWithGoogle() {
    GoogleSignInOptions gsio = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getOwnerActivity().getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    GoogleSignInClient gsic = GoogleSignIn.getClient(getContext(), gsio);
    Intent sii = gsic.getSignInIntent();
    getOwnerActivity().startActivityForResult(sii, GOOGLE_SIGN_IN_REQUEST_CODE);
}

public void credentialsFromGoogleIntent(@Nullable Intent data) {
    Task<GoogleSignInAccount> accountTask =
            GoogleSignIn.getSignedInAccountFromIntent(data);
    accountTask.addOnCompleteListener(receiveAuthInfo -> {
        if (receiveAuthInfo.isSuccessful()) {
            GoogleSignInAccount account = accountTask.getResult();
            AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
            auth.signInWithCredential(credential).
                    addOnCompleteListener(completeSignIn -> {
                        if (!completeSignIn.isSuccessful()) {
                            Log.w("LoginWindow", "signInWithCedential:Failure", completeSignIn.getException());
                            return;
                        }
                        CollectionReference reference = db.collection(USER_COLLECTION);
                        FirebaseUser user = auth.getCurrentUser();
                        Query query = reference.whereEqualTo("uuid", user.getDisplayName());
                        query.get().addOnCompleteListener(task -> {
                            if (task.getResult().size() <= 0) {
                                UserProfileChangeRequest.Builder build = new UserProfileChangeRequest.Builder();
                                String userId = UUID.randomUUID().toString();
                                build.setDisplayName(userId);
                                Task<Void> task1 = user.updateProfile(build.build());
                                Map<String, Object> userData = new HashMap<>();
                                userData.put("uuid", userId);
                                userData.put("password", "irrelevant");
                                Task<DocumentReference> task2 = reference.add(userData);
                                Tasks.whenAll(task1, task2).continueWith(taskContinue -> {
                                    Intent intent = new Intent(getOwnerActivity(),
                                            MainActivity.class);
                                    getOwnerActivity().startActivity(intent);
                                    return null;
                                });
                            } else {
                                Intent intent = new Intent(getOwnerActivity(),
                                        MainActivity.class);
                                getOwnerActivity().startActivity(intent);
                            }
                        });
                    });
        } else
            Log.w("LoginWindow", receiveAuthInfo.getException().toString());
    });
}

Comments

Comment posted by Natanoy

Actually, I have already regenerated the API key several times and updated the google-services.json file that’s included in my project subsequently. The exception remains the same. Is there another solution to this issue that you can think of?

Comment posted by DazWilkin

What is

Comment posted by DazWilkin

Ah, I guess

Comment posted by Natanoy

The google-services.json is the config file that you mentioned earlier.

Comment posted by docs

Yeah, sorry. I’m unfamiliar with the Android integration but I just read the

Android Tags:android, firebase-authentication, google-authentication

Post navigation

Previous Post: [FIXED] android – W/Firestore: (24.1.2) [CustomClassMapper]: No setter/field for about found on class
Next Post: [FIXED] android – FusedLocationProviderClient and LocationCallback() object queries

Related Posts

[FIXED] c# – Why does JSON.NET on Xamarin.Android never finish parsing and how can I fix this? Android
[FIXED] java – ‘Person()’ has private access in ‘android.app.Person’ Android
[FIXED] java – Storing favourite item from list into a SharedPreferences in android? Android
[FIXED] android – Kotlin `apply()` method analog in Dart Android
[FIXED] android – Xamarin Forms – Foreground Service – turn on redirection of phone calls Android
[FIXED] kotlin – How to know when one view is on top of another view based on co ordinates of that view in android Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What are the main features of Islamic education?
  • Is the Jeep 4xe worth it?
  • How does the ringer work on cast iron?
  • What is the biggest size interior door?
  • Is blue raspberry an original Jolly Rancher flavor?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme