2015-05-05 188 views
12

我在Android应用程序中集成了Google Places API。 我已阅读api文档See HereGoogle Places API总是返回错误

我已经激活了谷歌Places API的Android和生成的浏览器键 ,当我打电话API响应得到错误 -

{"error_message" : "This API project is not authorized to use this API.Please ensure that this API is activated in the APIs Console: Learn more: https://code.google.com/apis/console", 
    "html_attributions" : [], 
    "results" : [], 
    "status" : "REQUEST_DENIED" 
} 

我也尝试创建的Android按键,并将其返回 -

{ 
"error_message" : "This IP, site or mobile application is not authorized to use this API key.", 
"html_attributions" : [], 
"results" : [], 
"status" : "REQUEST_DENIED" 
} 

我没有得到我的代码中的问题。

任何帮助表示赞赏。提前致谢。

检查API控制台 - enter image description here

+0

你可以给你用过的网址? –

+0

@Sandeep Singh请检查此-https://maps.googleapis.com/maps/api/place/textsearch/json?query = SEARCH_STRING&key = API_KEY&radius = DIFINED_RADIUS&location = CURRENT_LAT,CURRENT_LONGI – Guess

+0

KISS使用正确的API密钥(浏览器密钥) –

回答

8

它看起来像你使用Places API Web服务,它需要启用 “谷歌Places API的Web服务”,并提供服务器密钥:https://developers.google.com/places/webservice/intro#Authentication

既然你”重新构建一个Android应用程序,你可能想尝试Android的Places API,我们刚刚在三月发布:)文档可在https://developers.google.com/places/android/

我希望这有助于!

+0

我试过这个,但我得到同样的错误。我已启用适用于Android的Places API。 –

+1

同意。启用Google Places API Web服务是必需的。 –

17

我有同样的问题。在我的情况下,问题是,我试图用简单的HttpURLConnection类通过这个网址发送请求:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=62.25227243964484%2C59.12338379770518&radius=500&key=my_key 

凡my_key是为谷歌Places API的为Android的关键,但是当我切换到谷歌Places API的网站服务,这工作正常。看来,使用键谷歌Places API的Android版,你应该按照本指南https://developers.google.com/places/android/

2

我按以下先决条件解决了这个问题:

1)确保您使用以下URL

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=YOURSEARCHTEXT&key=YOUR_SERVER_API_KEY。 请勿使用您的android/IOS API密钥。

2)确保您已在控制台中启用了以下API。

谷歌Places API的Web服务(付费服务)

+1

启用Google Places API网络服务(免费服务)..它为我工作... Thnkx @Shoaib –

+0

@AmitabhaBiswas +1免费服务也为我工作。我使用Android密钥同时启用了地点Android API和Places Web Service。 – Talha

+0

HapPy编码... –

0

使用Android的API是不是浏览器和服务器API密钥。面临同样的问题,但使用Android API密钥解决。

1

虽然使用谷歌地方api你的android API密钥将无法正常工作,创建一个服务器密钥,并在请求时使用该地址的URL服务器。在清单中,您的相同的android api密钥将会存在。这应该可以解决你的问题。

2

其实我也遭受了这个问题,但启用“Google Places API Web服务”为我工作。

问题是,我们正在使用Google Places的Web服务获取Places,并且我们忘记在Google开发者控制台中启用Google Places API Web Service

所以请确保每当你使用谷歌API的地点,不要忘记启用谷歌地图API的Android和谷歌Places API的Web服务

0

启用“谷歌地图地理编码API”启用“谷歌地图Android的API”后

1

这个我试过很多时候UTIL我找到了解决办法

,如果你将你的应用程序发送的网址,获取位置信息那么你正在使用 谷歌Places API的Web服务没有谷歌Places API的为Android

所以,你必须上启用API信息中心Google Places API Web Service,它会工作。

0

请确保您有 '谷歌Places API的Web服务' 启用,你必须使用一个服务器密钥(不是一个Android键)

Enable api

set credential