GoogleAPI异常中API_UNAVAILABLE与API_NOT_CONNECTED状态码的区别
Hey there! Let’s clear up the confusion between these two common Google API error states—they’re related but happen in totally distinct scenarios:
API_NOT_CONNECTED
This error means your app hasn’t established a connection to Google Play Services yet, or the existing connection was dropped and hasn’t been re-established.
Think of it like trying to send a text before you’ve turned on your phone’s cellular data:
- You’ll get this if you attempt to call a Google API (like Maps, Drive, or Sign-In) before initializing and connecting your
GoogleApiClient(or the newerGoogleSignInClient/ActivityResultContractsflow). - It can also pop up if the connection was lost unexpectedly (e.g., the user force-stopped Google Play Services in the background) and your app hasn’t implemented reconnection logic.
In short: Your app isn’t even talking to Google’s services yet.
API_UNAVAILABLE
This error occurs when your app is successfully connected to Google Play Services, but the specific API you’re trying to use isn’t accessible right now.
Common triggers include:
- The user’s device has an outdated version of Google Play Services that doesn’t support the API you’re calling (e.g., using a brand-new Maps feature on a device with Play Services from two years ago).
- The API is restricted in the user’s region (e.g., some Google Workspace APIs aren’t available in certain countries).
- The API hasn’t been enabled for your project in the Google Cloud Console (though this usually throws a more specific error, it can sometimes manifest as
API_UNAVAILABLE).
In short: You’re connected to Google’s services, but the specific tool you need is off-limits at the moment.
Quick Cheat Sheet
API_NOT_CONNECTED: No active connection to Play Services. Fix by ensuring you properly initialize and connect your client before making API calls.API_UNAVAILABLE: Connected to Play Services, but the target API can’t be used. Fix by checking Play Services version, region restrictions, or API enablement status in your project.
内容的提问来源于stack exchange,提问作者Shubham Hupare

