0

我是使用 Google api 最近的道路拍摄道路的新手。

我正在尝试如下链接:

最近道路的 Google api

如果我必须尝试

https://roads.googleapis.com/v1/nearestRoads?parameters&key=YOUR_API_KEY

使用我的项目中提供的 api 密钥,我得到

{
"error": {
    "code": 403,
    "message": "Roads API has not been used in project **** before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/roads/overview?project=*** then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.Help",
            "links": [
                {
                    "description": "Google developer console API activation",
                    "url": "https://console.developers.google.com/apis/api/roads/overview?project=****"
                }
            ]
        }
    ]
}

替换使用的密钥。

我在这里想念什么?我应该在使用前在某处验证密钥吗?或者,如果我只想试用样品,我该如何获得钥匙?

4

1 回答 1

1

“Roads API 之前没有在项目 **** 中使用过或已被禁用。通过访问https://console.developers.google.com/apis/api/roads/overview?project= *** 启用它然后重试. 如果您最近启用了此 API,请等待几分钟让该操作传播到我们的系统并重试。",

此错误消息有点令人困惑。在访问 API 之前,您需要在 Google 开发者控制台的项目中启用它。要做到这一点

  1. 转到https://console.developers.google.com/apis/dashboard
  2. 确保您的项目在顶部被选中。
  3. 去图书馆
  4. 搜索道路API
  5. 启用它。

等待几分钟,然后您的代码应该可以工作了

详细信息:

当你想访问谷歌数据时,谷歌需要知道你是谁。以及您的项目将要做什么。他们通过要求您在谷歌开发者控制台上创建一个项目来做到这一点。在该项目中,您可以定义将使用的 api,还可以请求 api 密钥和客户端 ID,这将允许您访问数据。在这种情况下,您在谷歌开发者控制台上设置项目时遇到问题,它与您的代码无关。

于 2018-05-29T09:18:51.967 回答