Couldn't connect to Google API client

后端 未结 7 690
无人共我
无人共我 2020-12-11 16:59

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 ma

相关标签:
7条回答
  • 2020-12-11 17:34

    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.

    0 讨论(0)
  • 2020-12-11 17:43
    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()
    
     }
    }
    
    0 讨论(0)
  • 2020-12-11 17:45

    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.

    0 讨论(0)
  • 2020-12-11 17:45

    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.

    0 讨论(0)
  • 2020-12-11 17:50

    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.

    0 讨论(0)
  • 2020-12-11 17:54

    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.

    0 讨论(0)
提交回复
热议问题