简体   繁体   English

呼叫方向 API 失败,状态为“REQUEST_DENIED”

[英]Call to Directions API failing with "REQUEST_DENIED" status

The.network response from the Google Directions API is returning an error:来自 Google Directions API 的网络响应返回错误:

{"error_message":"This IP, site or mobile application is not authorized to use this API key. Request received from IP address xxx.xx.x.xx, with empty referer","routes":[],"status":"REQUEST_DENIED"} {“error_message”:“此 IP、站点或移动应用程序未被授权使用此 API 密钥。请求从 IP 地址 xxx.xx.x.xx 收到,引用为空”,“路由”:[],“状态” :“请求被拒绝”}

I believe the.networking code is correct:我相信 .networking 代码是正确的:

override suspend fun getDirections(origin: LatLng, destination: LatLng): Result<JSONObject> = suspendCoroutine { continuation ->                                                                                           
val request = Request.Builder()                                                                                                                                                                                        
    .url("https://maps.googleapis.com/maps/api/directions/json?origin=${origin.latitude},${origin.longitude}&destination=${destination.latitude},${destination.longitude}&key=......")
    .build()                                                                                                                                                                                                           
                                                                                                                                                                                                                       
okHttpClient.get().newCall(request).enqueue(object : Callback {                                                                                                                                                        
    override fun onFailure(call: Call, e: IOException) {                                                                                                                                                                                                                                                                                                 
        continuation.resume(                                                                                                                                                                                           
            Failure(CustomError(e.localizedMessage ?: genericErrorMsg, true, error = e)))                                                                                                                              
    }                                                                                                                                                                                                                  
                                                                                                                                                                                                                       
    override fun onResponse(call: Call, response: okhttp3.Response) {                                                                                                                                                  
        if (response.isSuccessful && response.body != null) {                                                                                                                                                          
            val jsonObject = JSONObject(response.body!!.string())                                                                                                                                                      
            continuation.resume(Success(jsonObject))                                                                                                                                                                   
        } else {                                                                                                                                                                                                       
            continuation.resume(Failure(CustomError(response.message)))                                                                                                                                                
        }                                                                                                                                                                                                              
    }                                                                                                                                                                                                                  
})                                                                                                                                                                                                                     
}                                                                                                                                                                                                                          

..and the API credentials appear to be configured appropriately: ..并且 API 凭证似乎配置正确:

Additionally, the same API key has been and continues to be used for the Google Places SDK:此外,相同的 API 密钥已经并将继续用于 Google Places SDK:

// Initialize Places SDK.
Places.initialize(applicationContext, ".....")

Why is the Directions API returning an error?为什么 Directions API 返回错误?

In your example, you are not using an Android SDK, but have a key restriction set specifying that you are.在您的示例中,您没有使用 Android SDK,但是有一个密钥限制集指定您是。

I would recommend proxying the directions service so that your key cannot be extracted from your app.我建议代理路线服务,以便您的密钥无法从您的应用程序中提取。

See Using Google Maps Directions API in android - what kind of API key is needed?请参阅android 中的使用 Google 地图方向 API - 需要什么样的 API 密钥?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谷歌地图方向 API 空白回复 - Google Maps Directions API blank response 请求仍然失败 WSO2 API Manager 3.2.0 高可用性端点 - Request still failing with WSO2 API Manager 3.2.0 high availability endpoints 为什么在从 API 服务器调用 AWS Athena API 时出现 ThrottlingException - Rate Exceeded status:400? - Why do I get ThrottlingException - Rate Exceeded status:400 when making AWS Athena API call from API server? 在 Flutter 是否可以在 firebase Messaging BackgroundHandler 中调用 API 请求? - In Flutter Is that possible to call API request in firebase Messaging BackgroundHandler? SendGrid API 状态 - SendGrid API Status Npm 发布失败并出现 400 错误请求 - Npm publish is failing with 400 Bad Request 仅在谷歌应用程序脚本中获取请求失败 - Fetch request failing in google apps script ONLY 从 CURL 示例实现 Twilio Api 调用 js 返回状态码 200 但似乎没有更新数据 - Implementing Twilio Api call from a CURL example to js returns status code of 200 but does not seem to update data 请求永远被拒绝 - 请求增加 Google Cloud 中的 GPU 配额 - Request Denied forever - request gpu quota increase in Google Cloud EFS 安装因 mount.nfs4 失败:服务器拒绝访问 - EFS mount failing with mount.nfs4: access denied by server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM