【问题标题】:Couldn't connect to Google API client无法连接到 Google API 客户端
【发布时间】:2015-08-19 10:36:26
【问题描述】:

我无法获取最后一个已知位置。 我在谷歌控制台中启用了 Geocoding APIGoogle Places API for Android。 我在清单文件中添加了 api 密钥:

<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" />

但我一直在控制台中收到一条消息:“无法连接到 Google API 客户端:ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}


更新

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();
}

onConnectedonConnectionFailed 不调用。

我也使用Android-ReactiveLocation 但两种方法都输出到控制台:无法连接到 Google API 客户端:ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}

【问题讨论】:

  • 请发布您的代码。

标签: android google-play-services android-geofence


【解决方案1】:

我遇到了同样的问题

Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}

因为Google Places API for Android 未在 API 控制台中启用。

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

【讨论】:

  • 但是我已经为 Android 启用了 Google Places API,我写过它
  • @Elenasys :我在生产中也遇到了同样的问题,并且在开发中构建它的工作正常。提前致谢。
【解决方案2】:

我在这里遇到了类似的问题。 虽然我没有专门使用任何 Google API,但我也遇到了这个错误。

我的场景是:我正在制作一个可穿戴应用程序,并且想将 DataItem 从手机发送到可穿戴设备。为此,我使用了 GoogleApiClient 和 Wearable.DataApi。

经过数小时努力解决问题后,我来到了这个帖子:https://android-developers.googleblog.com/2014/10/tips-for-error-handling-with-android.html

文章中对我很重要的部分是:

在没有可用的 Android Wear 配套应用程序或设备时请求 Wearable.API。

所以,我解决了在手机上安装 Companion App 的问题:https://play.google.com/store/apps/details?id=com.google.android.wearable.app

安装后,ResultCallback 开始返回成功。

【讨论】:

  • 同样的问题,缺少穿戴伴侣应用程序。
【解决方案3】:

您是否在 google 控制台开发人员中启用了地点 API? (在 API & Auth 菜单中)。 您是否选择了 Android API 密钥?

它对我来说很好,所以我不知道它会是什么。

【讨论】:

  • 是的,我已经为 Android 启用了 Google Places API,我写过它。是的,我选择了一个 android API 密钥。
【解决方案4】:

您尚未在控制台上激活 Google+ Api。

如果您想使用任何其他 API,但需要用户使用 Google+ 帐户登录,则必须启用它。

希望它有效。

【讨论】:

    【解决方案5】:

    我在使用 Google Fit API 时遇到了同样的问题。使用与您描述的非常相似的设置,我收到了相同的错误消息:

    无法连接到 Google API 客户端: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}

    问题最终出在与 Google 登录服务通信的配置上。我在找到 Google 文档后解决了这个问题: Start Integrating Google Sign-In into Your Android App。我使用“获取配置文件”部分获取有关为我的密钥库检索 SHA1 哈希的说明,然后使用“获取配置文件”按钮启动 Google 开发人员控制台进程以创建一个 JSON 文件,该文件被放入“/ app" Android 应用程序的目录。

    【讨论】:

      【解决方案6】:

      我的应用使用 Google Drive API,我遇到了同样的问题“在某些设备上无法连接到 Google API 客户端:ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}。建议去通过Start Integrating Google Sign-In into Your Android App 帮助但让我很困惑:
      google-services.json 如何影响生成的 apk?我应该对发布证书等做同样的事情吗?...
      最终我发现了幕后的东西,another answer 透露 google-services.json 只是可选的。

      所以这些步骤帮助了我:

      1. 打开Google Developer Console 并打开/创建一个项目
      2. 在侧边菜单中打开“API 管理器”
      3. 点击左栏中的“凭据”
      4. 'Add credentials' -> 'OAuth 2.0 client ID' -> 'Android' 并为每个可用于签署您的应用程序的证书填写它,即:发布证书、Jenkins 调试证书、本地调试证书

      另外不要忘记检查您的项目中是否启用了相应的 API(参见步骤 #1)

      在通过Start Integrating Google Sign-In into Your Android App 生成 google-services.json 期间,会隐式创建相同的“OAuth 2.0 客户端 ID”。

      【讨论】:

        【解决方案7】:
        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()
        
         }
        }
        

        【讨论】:

          猜你喜欢
          • 2016-12-08
          • 2018-02-18
          • 1970-01-01
          • 2018-03-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-06-06
          • 2022-10-20
          相关资源
          最近更新 更多