我正在使用google autocomplete place api。
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=“我的Android密钥”& input = Mg%20Ro& components = country:IN
我从控制台生成的密钥是Android密钥
我在Google API控制台中启用的API
Google Places API Web Service
Google Places API for Android
Google Maps Android API
和SHA-1指纹是debug-keystore。 现在点击,我得到这个链接的输出是
{"error_message":"This IP, site or mobile application is not authorized to use this API key. Request received from IP address 122.177.199.201, with empty referer","predictions":[],"status":"REQUEST_DENIED"}
在Server-Key的情况下,我得到了正确的回复
{"predictions":[{"description":"MG Road Metro Station","id":"9db78081a8f0e59874d51baff0df2c007e8c8dde","matched_substrings":[{"length":2,"offset":0}],"place_id":"ChIJY8G_aiIZDTkRohS7EKRePsw","reference":"CjQkAAAAj-nav4S-WWDQfmK7D5V_uc6XT8s5wZzsKNLQMHA7ucgRD_AGu5uIoxvWlxtpJaAiEhDOj61RTKbD9lK28Seovch6GhSPoMA7WPxS6v8ApRf_q03TtnzzrQ","terms":[{"offset":0,"value":"MG Road Metro Station"}],"types":["transit_station","point_of_interest","establishment","geocode"]},{"description":"M G Road Metro Station, Mehrauli-Gurgaon Road, Sector 28, Gurgaon, Haryana, India","id":"041408b314da313beac2e2016c697a9aba451be8","matched_substrings":[{"length":22,"offset":0}],"place_id":"ChIJATH6EiIZDTkR-aEggPmaDrU","reference":"CmRgAAAAEMJLJnkGwPSnN5BmE7_IU_UTEAxRT83T2IuHGKja7PouwUxH6j6gVzPlWiSi-yPgYH1vEUs_wiLMME2QbSkOBACPdtQmPdjQ5q-BlLxL3d81UOvaD8-jtvgrKOLLF_dPEhCRDuiBXJ90DQMY7ioJsQxnGhSFULVBF754FuwF2LFwzWTvlxmVoQ","terms":[{"offset":0,"value":"M G Road Metro Station"},{"offset":24,"value":"Mehrauli-Gurgaon Road"},{"offset":47,"value":"Sector 28"},{"offset":58,"value":"Gurgaon"},{"offset":67,"value":"Haryana"},{"offset":76,"value":"India"}],"types":["transit_station","point_of_interest","establishment","geocode"]},{"description":"MGF MAll Management, DLF City Mall Parking Road, Sector 28, Gurgaon, Haryana, India","id":"c8e8961eb24684f8fa6457876e0f5c1d7c38b5b9","matched_substrings":[{"length":2,"offset":0}],"place_id":"ChIJS3fMbyIZDTkRkexzrN-6sBg","reference":"CnRhAAAApKaoK6e148xwbkJZGhNXNTTDqStbf3vU5b0udThzC0jcdbtJceqWXcQ-I8U_x838GYjHTLLcNNswfrTu3jYVgnA-evtNfhN1pRKnugpvOAtonL2aEYmxGHQadW3bY8uzf-ERjosRBicEb2HfdoKZPhIQvUrFQqXv67CoiaWqlVqXUxoUBccSCK3csfVr1HA0H2HZOiqEmu8","terms":[{"offset":0,"value":"MGF MAll Management"},{"offset":21,"value":"DLF City Mall Parking Road"},{"offset":49,"value":"Sector 28"},{"offset":60,"value":"Gurgaon"},{"offset":69,"value":"Haryana"},{"offset":78,"value":"India"}],"types":["establishment"]},{"description":"MGF Infratech, Gurgaon, Haryana, India","id":"1b4b1ce2e29a7a8f3b3d07192bf06f7e6f0df84f","matched_substrings":[{"length":2,"offset":0}],"place_id":"ChIJTytQ6hgZDTkR2p2nzYt9tfA","reference":"CkQ1AAAAgAsxqmineUN1diGhpF5khDroggPvicHj5VlegMg-SYKf3ORdoFU5JB9dp5lpRY5byp9LAIx3alsDZ0k4D5QCrxIQXi5gMF1JakSfbAufPMlvcRoUqMmrZiUzEmhdiVxMBneGKFLrmZg","terms":[{"offset":0,"value":"MGF Infratech"},{"offset":15,"value":"Gurgaon"},{"offset":24,"value":"Haryana"},{"offset":33,"value":"India"}],"types":["establishment"]},{"description":"MG Road, National Highway 236, Maruti Housing Colony, Gurgaon, Haryana, India","id":"20c271b151605328170192b769e72e3e9bee6056","matched_substrings":[{"length":2,"offset":0}],"place_id":"ChIJrYoVEyIZDTkRcmM4_rRo_OE","reference":"CmRcAAAAtEh471bANMlFV-mDp2hOSVxW0_XxmNFQEmGXCiuZxvjsLvOcoyMPC0VhOifD7ngb-2rs5cfplaomYupeARu3kKEf6WPBQ170Ge7ZRNscQ1PDx12EvHkm4R7MrUD2F_kZEhBq6yvt7WzJgAkdXholeEObGhTuXqJl41XcSz2dzzksTMsHsU7Nzg","terms":[{"offset":0,"value":"MG Road"},{"offset":9,"value":"National Highway 236"},{"offset":31,"value":"Maruti Housing Colony"},{"offset":54,"value":"Gurgaon"},{"offset":63,"value":"Haryana"},{"offset":72,"value":"India"}],"types":["transit_station","point_of_interest","establishment","geocode"]}],"status":"OK"}
我无法理解为什么放置api不能用于Android-Key的情况。请有人试着解释一下。
谢谢
答案 0 :(得分:0)
首先,尝试更改现有的Android密钥选项或创建没有包名称和指纹限制的新密钥。如果它可以工作,那么你的包名可能有错误(.debug后缀自动添加到调试版本中的包名)
还要确保您已在清单中添加了Android密钥
答案 1 :(得分:0)
对于google api,在点击api时需要服务器密钥。使用sha1指纹创建服务器密钥,并将该密钥用于google places api。并在明确使用api键那里。不要混淆api密钥和服务器密钥。
在地方api的清单和服务器密钥中使用android密钥。创建SERVER密钥的Afetr等待5分钟。然后将启用您的服务器密钥
StringBuilder sb = new StringBuilder(PLACES_API_BASE+TYPE_AUTOCOMPLETE+OUT_JSON);
sb.append("?key=" + API_KEY);
sb.append("&types=(cities)");
sb.append("&input=" + URLEncoder.encode(input, "utf8"));
这里你必须使用API_KEY是SERVER key NOT ANDROID key