I can't fetch last known location. I have enabled Geocoding API and Google Places API for Android in google console. I added api key to manifest file:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_api_key" />
but I keep getting a message in the console: "Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}"
UPDATE
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
public void onConnected(Bundle connectionHint) {
Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
Toast.makeText(this, "Latitude = " + mLastLocation.getLatitude() + "\n" +
"Longitude = " + mLastLocation.getLongitude(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(this, connectionResult.toString(), Toast.LENGTH_LONG).show();
}
onConnected and onConnectionFailed do not call.
And also I use Android-ReactiveLocation but both methods are output to the console: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}
I had the same problem
Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}
because Google Places API for Android
was not enabled in the API Console.
I had a similar issue here. Although I was not using any Google API specifically, I was having this error too.
My scenario was: I was making a Wearable App, and wanted to send DataItem from phone to wearable. In order to do that, I was using GoogleApiClient and Wearable.DataApi.
After many hours struggling to solve the problem, I came to this post: https://android-developers.googleblog.com/2014/10/tips-for-error-handling-with-android.html.
The part on the article that was important to me was:
When requesting Wearable.API when no Android Wear companion application or device is available.
So, I solved the problem installing the Companion App on the phone: https://play.google.com/store/apps/details?id=com.google.android.wearable.app
After installing it, the ResultCallback started to return success.
Have you enabled the place API in the google console developer ? (in the API & Auth menu). Have you selected an android API key ?
It works fine for me so I don't know what it could be otherwise.
You haven't activated Google+ Api on the console.
If you want to use any other API but you'll need the user to login with a Google+ account, you'll have to enable it.
- Login here: https://console.developers.google.com/project?authuser=0
- Choose your project
- Find "APIs and Auth" on the left
- Click on API
- On this list, you'll see many APIs available.
Hope it works.
I ran into the same issue with utilization of the Google Fit API. With a very similar setup to what you describe, I received the same error message:
Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}
The issue ended up being the configuration for communications with the Google Sign-In service. I resolved this issue after finding the Google documentation: Start Integrating Google Sign-In into Your Android App. I used the "Get a Configuration File" section for instructions on retrieving the SHA1 hash for my keystore, then used the "Get a Configuration File" button to initiate the Google Developer Console process to create a JSON file that was placed into the "/app" directory of the Android application.
My app uses Google Drive API, and I faced the same issue "Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null} on some devices. Advice to go through Start Integrating Google Sign-In into Your Android App helped but left me really confused:
How google-services.json influences on resulting apk? Should I do the same for release certificate and so on?...
Eventually I found what is behind the scene and another answer reveals that google-services.json is just optional.
So these steps helped me:
- Open Google Developer Console and open/create a project
- In side menu open 'API Manager'
- On left column tap on 'Credentials'
- 'Add credentials' -> 'OAuth 2.0 client ID' -> 'Android' and fill it for each certificate that can be used for signing your app, i.e.: release certificate, Jenkins debug certificate, local debug certificate
Also don't forget to check that corresponding API is enabled in your project (see step #1)
During generating google-services.json via Start Integrating Google Sign-In into Your Android App the same 'OAuth 2.0 client ID' is created implicitly.
import com.google.auth.oauth2.{GoogleCredentials, ServiceAccountCredentials}
import com.google.cloud.bigquery._
class XYZRawDataIngestion {
def run(): Unit = {
var credentials: GoogleCredentials = null
val client_id: String = "10754111315596"
val client_email: String = "csp-302@xyz.com"
val private_key = "-----BEGIN PRIVATE KEY-----\nMII9xE9wTn68bxG8W60yU4O+JdullsTX\naOCrYTyVsTK+U78ElELXSqKn+Mqqka/IAS9ETCutLXhMNbTHbDUoN6POzU1c7GGz\nxSAmSXzVz6ejoJ9zoZXCB+cEI/CCne+GoGzg+CUCgYEAuGFxjuFNEAJbOamo6zWu\n/MobrYwqg4W4akwe4bgFE9lbpb3qs5pKhxGz0Utn3fNyhsTwQvgJ5oCBVIRxZwzv\nM8+4aHXGMJLNMf6EpUeoOCWOcp+6kLFNZZF9erUU1d3m+ID4Df4AUijIIG6lUQa1\nLP4eCwDeNpJGFcTQuz18u+U=\n-----END PRIVATE KEY-----\n"
val private_key_id: String = "79072ec47cc5a70bb4f2da1ccd4a"
val project_id = "xyz-mgmt"
val token_uri = new URI("https://oauth2.googleapis.com/token")
credentials = ServiceAccountCredentials.fromPkcs8(client_id, client_email, private_key, private_key_id,
null, null, token_uri)
val bigquery: BigQuery = BigQueryOptions.newBuilder.setCredentials(credentials).setProjectId(project_id).build().getService()
}
}
来源:https://stackoverflow.com/questions/30650231/couldnt-connect-to-google-api-client