0

我正在开发一个使用 Places API 检索信息并将其显示在地图上的 Android 应用程序。检索场所的初始请求失败,并显示来自 HTTP 请求的 ACCESS_DENIED 状态消息。下面是我用来生成请求的代码:

try { 

HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
        HttpRequest request = httpRequestFactory
                .buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
        request.getUrl().put("key", API_KEY);
        request.getUrl().put("location", _latitude + "," + _longitude);
        request.getUrl().put("radius", _radius); // in meters
        request.getUrl().put("sensor", "false");
        if(types != null)
            request.getUrl().put("types", types);

        PlacesList list = request.execute().parseAs(PlacesList.class);
        // Check log cat for places response status
        Log.d("Places Status", "" + list.status);
        return list;

在另一个 Stackoverflow 帖子中,有人建议发布者尝试以下方法来测试他们的密钥:

转到此处的 api 控制台,然后转到 SERVICES。单击活动服务选项卡并确认“Places API”已打开。点击 ? 旁边的“尝试”链接。它应该使用您的密钥创建一个正确的 URL,该 URL 应该可以工作。比较您尝试的链接与此 URL 的差异。

我按照这些说明进行操作。基于我在单击 ? 时收到以下结果的事实 要“尝试”链接,我怀疑 API 密钥存在根本问题,与代码无关……否则我会认为我会得到 SUCCESS 而不是 REQUEST_DENIED:

{
  "html_attributions" : [],
  "results" : [],
  "status" : "REQUEST_DENIED"
}

我通过输入我的调试证书的 SHA1 获得了我的密钥(我使用带有所有适当参数的 Keytool...例如,androiddebugkey ....debug.keystore)后跟一个“;” 和应用程序的包名称。

不知道问题是什么......我确定这很简单,但我没有看到它并且我被卡住了。想法?

4

1 回答 1

0

我从未收到对此帖子的回复,因此最终我通过在新项目名称下创建一个全新的密钥来解决问题,并且我至少能够从 Google 检索地点。我仍然遇到填充地图的问题,但是这可能是代码问题。

我注意到我使用的那个给我 ACCESS DENIED 结果的密钥的标题是:“Android 应用程序的密钥(带有证书)”,并且在实际密钥下方列出了一个标签“Android 应用程序:”。关键值是SHA1值“;” 后跟包名称。而我在最终工作的新项目名称(Places API)下创建的密钥的标题为:“浏览器应用程序的密钥(带有引用者)”,标签为“引用者:”,值为“允许任何引用者” .

So there is definitely something different about these two keys. I'm not sure what I did differently when I generated the keys. I'd like to understand what I did to generate these two "different" types of keys so that I and perhaps others won't repeat my "mistake(s)".

There are many references to creating keys in the Google documentation. The fact that there are so many postings regarding problems with the keys tells me that the Google documentation is not very clear otherwise so many issues wouldn't exist on this topic.

于 2013-04-01T16:39:26.583 回答