7

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

I use google sample

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}

makaron
  • 77
  • 1
  • 1
  • 8

7 Answers7

4

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.

https://developers.google.com/places/android/signup

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
2

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.

Loubake
  • 71
  • 2
  • Same issue here with missing wear companion app. – clearpath Jul 29 '19 at 13:01
  • After applying your solution I got success as well. But I am not able to find nodes in the callback capabilityInfoTask.addOnCompleteListener { task -> if (task.isSuccessful) { //AFTER YOUR SOLUTION I GOT SUCCESS HERE val capabilityInfo = task.result nodes = capabilityInfo.nodes // HERE nodes are empty list } } – ahjo4321hsotuhsa Aug 28 '23 at 19:54
0

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.

IvannMG
  • 41
  • 4
  • Yes, I have enabled Google Places API for Android, I wrote about it. Yes, I have selected an android API key. – makaron Jun 04 '15 at 18:59
0

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.

Hope it works.

George
  • 6,886
  • 3
  • 44
  • 56
0

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.

chicagoCrazy
  • 374
  • 1
  • 4
  • 12
0

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:

  1. Open Google Developer Console and open/create a project
  2. In side menu open 'API Manager'
  3. On left column tap on 'Credentials'
  4. '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.

Community
  • 1
  • 1
demaksee
  • 1,108
  • 11
  • 16
0
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()

 }
}
ppreetikaa
  • 1,149
  • 2
  • 15
  • 22
Rajiv Singh
  • 958
  • 1
  • 9
  • 14