skip to Main Content

I tried setting up an API-key for Google Cloud that can be used from my Expo-managed android app. I got the fingerprint by running eas credentials and set the restriction in Google Cloud to only Match android apps with this fingerprint.

When implementing react-native-geocoding, I got the following error when trying to fetch data from the API:

this ip, site or mobile application is not authorized to use this api key. request received from ip address XX.XX.XX.XXX, with empty referer with status REQUEST_DENIED.

When I remove the restrictions for the API-key, I can easily access the API.

What could be causing this? Am I maybe using the wrong fingerprint for the development version? If so, where can I find the correct one?

2

Answers


  1. My guess is the error occurs because the API key restrictions you’ve set up don’t match the fingerprint of your development app. When running your app in development mode, it often uses a different keystore than the production build, resulting in a different SHA-1 fingerprint.

    Try running the following command –

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

    which will display the SHA-1 fingerprint you need. Then add this SHA-1 fingerprint to your API key restrictions in the Google Cloud Console.

    Login or Signup to reply.
  2. It seems like the issue could be related to the fingerprint you’re using for the API key restriction. To ensure you’re using the correct fingerprint, follow these steps:

    Set up signingConfig in build.gradle: In your app/build.gradle file, make sure you have a signingConfig block properly configured, even for debug builds. For example:

    signingConfigs {
        release {
            storeFile file('YOUR_KEYSTORE_PATH') // Path to your release keystore
            storePassword 'YOUR_STORE_PASSWORD' // Keystore password
            keyAlias 'YOUR_KEY_ALIAS' // Alias for your release key
            keyPassword 'YOUR_KEY_PASSWORD' // Password for your release key
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
    

    }
    Run the signingReport command: Use the following command to generate the fingerprints:

    ./gradlew signingReport
    

    This will output the SHA-1 and SHA-256 fingerprints for your debug and release keys in the terminal. Use the correct SHA-1 fingerprint for the environment you’re working in (debug or release) to configure the API key restrictions in the Google Cloud Console.

    Update the API key restrictions: Go to the Google Cloud Console and update the restrictions for your API key, adding the correct SHA-1 fingerprint and the package name.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search