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
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 –
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.
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:
}
Run the signingReport command: Use the following command to generate the fingerprints:
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.