发布应用后Google Maps/Places API无法使用,授权失败该如何解决?
Hey there, let's dig into this authorization failure issue that's breaking your Maps and Places API functionality post-launch—total bummer when this happens after you've shipped your app. The LogCat error clearly points to an authorization problem, so let's walk through the most common fixes step by step:
Double-check your API key's SHA-1 & package name bindings
This is the #1 culprit for post-launch authorization issues. When you build your release APK, it uses a different signing key than your debug build. Head to your Google Cloud Console, find the API key you're using, and make sure you've added the release SHA-1 fingerprint (not just the debug one) along with your app's exact package name. Even a tiny typo here will block authorization.Verify that required APIs are enabled in Cloud Console
It's easy to overlook this: ensure both the Maps Android API and Places API are toggled on in your Google Cloud project. Sometimes APIs get disabled accidentally, or you might have enabled them for a different project by mistake.Inspect your AndroidManifest.xml configuration
Confirm the API key metadata tag is correctly placed inside the<application>tag and that the key string matches exactly what's in Cloud Console. Here's the correct format to reference:<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_ACTUAL_API_KEY"/>Also, make sure you haven't mixed up the metadata name (it's
com.google.android.geo.API_KEYfor both Maps and Places, not the oldcom.google.android.maps.v2.API_KEY).Check for API key restrictions or quota limits
If your key has IP or application restrictions that don't align with your release build, it'll fail. Additionally, even though authorization errors are rarely quota-related, it's worth checking if you've hit the daily quota for either API in Cloud Console's "Quota" section.Regenerate your API key (as a last resort)
Sometimes keys can become corrupted or have hidden misconfigurations. Delete your current key, create a new one, reattach the correct SHA-1 and package name, update it in your app, and rebuild the release APK.
Since you mentioned trying xomena's suggestions without luck, focusing tightly on the authorization flow (especially release-specific signing details) should get you past this. Let me know if any of these steps need more clarification!
内容的提问来源于stack exchange,提问作者Federico Pennino

