Couldn't connect to Google API client

青春壹個敷衍的年華 提交于 2019-11-28 13:32:43

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

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.

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.

demaksee

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.

Rajiv Singh
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()

 }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!