“此 API 项目无权使用此 API” 使用 Google-Directions-Android

“This API project is not authorized to use this API” using Google-Directions-Android

我正在使用 Google-Directions-Android (https://github.com/jd-alexander/Google-Directions-Android) 构建应用程序。我在同一个应用程序中使用 API 键来制作地图没有问题,但是当我尝试使用以下

  Routing routing = new Routing.Builder()
                .travelMode(AbstractRouting.TravelMode.DRIVING)
                .key(getString(R.string.google_api_key))
                .withListener(this)
                .alternativeRoutes(false)
                .waypoints(new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude()), pickupLatLng)
                .build();
        routing.execute();

我得到一个错误“This API project is not authorized to use this API”。 在我的 Google API 控制台中,我启用了所有 16 个地图 API,唯一被请求的是 Android 的 Maps SDK。 API键完全开放,不受限制。有什么提示吗?

要使用 google 方向库,您必须使用您的服务器密钥(自动为您生成 google)。 您可以在控制台中找到服务器密钥

尝试替换此代码:

.key(getString(R.string.google_api_key))

使用服务器密钥 - 像这样:

.key(getString("your server key"))