【问题标题】:"This ip site or mobile application is not authorized to use this api key"“此 ip 站点或移动应用程序无权使用此 api 密钥”
【发布时间】:2018-09-11 06:11:20
【问题描述】:

我使用这个https://github.com/akexorcist/Android-GoogleDirectionLibrary 库,我的代码在下面;

 GoogleDirection.withServerKey("MyApiKey")
            .from(new LatLng(Double.parseDouble(work.getAxCor()), Double.parseDouble(work.getAyCor())))
            .to(new LatLng(Double.parseDouble(work.getBxCor()), Double.parseDouble(work.getByCor())))
            .execute(new DirectionCallback() {
                @Override
                public void onDirectionSuccess(Direction direction, String rawBody) {
                    if(direction.isOK()) {

                        Route route = direction.getRouteList().get(0);
                        Leg leg = route.getLegList().get(0);
                        Info distanceInfo = leg.getDistance();
                        Info durationInfo = leg.getDuration();
                        distance = distanceInfo.getText();
                        duration = durationInfo.getText();

                    } else {

                    }
                }

                @Override
                public void onDirectionFailure(Throwable t) {
                    // Do something
                }
            });

但我得到一个错误““此 ip 站点或移动应用程序无权使用此 api 密钥”。显示地图。地图上没有问题。启用地理编码、地理定位和地点 Api。谢谢。

【问题讨论】:

  • 只需共同确认您已按照此处的步骤操作:developers.google.com/maps/documentation/directions/get-api-key?它说During development and testing, you can register a project for testing purposes in the Google Cloud Platform Console and use a generic, unrestricted API key. When you are ready to move your app or website into production, register a separate project for production, create a server-restricted API key, and add the key to your application. 您是否创建了服务器受限的 API 密钥而不是测试一个?如果是,那么您可能需要指定允许的 IP 等。
  • 感谢您的回复。是的,我有两个单独的 api 键,并且都可以与谷歌地图一起正常工作。但不幸的是,不要使用这个库。
  • 如果你看到他们的AndroidManifest 示例应用程序文件,他们也在那里定义了它。也许你也需要在那里改变:github.com/akexorcist/Android-GoogleDirectionLibrary/blob/…。如果这不起作用,开发人员可能能够提供更好的帮助,所以也许可以在 github repo 上打开一个问题。

标签: android api google-maps


【解决方案1】:

Directions API 它是一个web service,不能应用捆绑限制。

the documentation,您可以使用代理、混淆密钥或证书固定。

【讨论】:

    猜你喜欢
    • 2014-03-22
    • 2014-07-19
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2014-06-03
    • 2014-07-15
    • 2014-06-10
    • 1970-01-01
    相关资源
    最近更新 更多