【问题标题】:this api project is not authorized to use this API此 api 项目无权使用此 API
【发布时间】:2019-03-03 00:15:46
【问题描述】:

我做了一个出租车预订项目,它使用 google maps api 来定位出租车、接送地点。

问题是当我叫车时出现以下错误:

This API project is not authorized to use this API

请注意,我已启用所有 google map api 服务,然后重新生成密钥,问题仍然存在。

如何解决?

【问题讨论】:

标签: android api google-maps


【解决方案1】:

您需要在 google 开发者控制台中启用所需的 API:https://console.developers.google.com/

在左上角选择您的项目,然后单击仪表板中的“启用 API 和服务”按钮。

请注意,根据您的要求,您可能需要启用超过 1 个 API(路线、地理定位、地理编码等)。

【讨论】:

    【解决方案2】:

    我找到了答案,

    问题出在我的代码中:

    public void requestDirection() {
    
            snackbar = Snackbar.make(view, getString(R.string.fare_calculating), Snackbar.LENGTH_INDEFINITE);
            snackbar.show();
            GoogleDirection.withServerKey(getString(R.string.google_api_key))
                    .from(origin)
                    .to(destination)
                    .transportMode(TransportMode.DRIVING)
                    .execute(this);
    
            confirm.setEnabled(false);
        }
    

    R.string.google_api_key's 的值由来自strings.xml 的另一个键提供。现在,我直接给 withServerKey 赋值,直到我发现我的strings.xml.

    有问题
    public void requestDirection() {
    
            snackbar = Snackbar.make(view, getString(R.string.fare_calculating), Snackbar.LENGTH_INDEFINITE);
            snackbar.show();
            GoogleDirection.withServerKey("[api key]")//getString(R.string.google_api_key))
                    .from(origin)
                    .to(destination)
                    .transportMode(TransportMode.DRIVING)
                    .execute(this);
    
            confirm.setEnabled(false);
        }
    

    【讨论】:

      【解决方案3】:

      如果您认为您已启用所有功能,那么您可能会错过更改您的 manifest.xml 文件,例如:

              <meta-data
                  android:name="com.google.android.geo.API_KEY"
                  android:value="@string/google_maps_key" />
              <meta-data
                  android:name="com.google.android.gms.version"
                  android:value="@integer/google_play_services_version" /> 
      

      application标签下添加这些标签

      【讨论】:

      • 我添加了那些标签,重建/清理项目,但问题仍然存在:(
      【解决方案4】:

      如果你点击折线 Api 来解决这个问题:

      https://console.developers.google.com/google/maps-apis/apis/directions-backend.googleapis.com/metrics?project=light-router-266008

      需要启用 API:

      1. 地理位置 API
      2. 路线 API

      【讨论】:

        猜你喜欢
        • 2019-05-21
        • 2014-04-13
        • 2016-10-29
        • 2016-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多