简体   繁体   English

Google Places API响应状态为“ Request_Denied”

[英]Google Places API Response status “Request_Denied”

I am using Google Places API for my iOS application.I have enabled Google Maps Android API v2, Places API from API Console.Create an iOS key in API access section. 我正在为我的iOS应用程序使用Google Places API。我已经从API控制台启用了Google Maps Android API v2,Places API。在API访问部分中创建iOS密钥。 I am making a request to the Google Places API, using the following code: 我正在使用以下代码向Google Places API发出请求:

NSString *finalString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=5000&keyword=restaurants&sensor=false&key=PASTE_GENERATED_KEY_HERE",_location.coordinate.latitude,_location.coordinate.longitude];

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:finalString]];

But I am getting following in JSON Response 但是我在JSON Response中得到关注

{
    "debug_info" =     (
    );
    "html_attributions" =     (
    );
    results =     (
    );
    status = "REQUEST_DENIED";
}

I have regenerated the new key which is not working as well. 我已经重新生成了新的密钥,它不能正常工作。 Can someone please figure out what I am doing wrong here. 有人可以在这里弄清楚我在做什么错。

"...The Google Places API does not currently support iOS keys generated from the Google APIs Console. Only Server and Browser keys are currently supported.." “ ... Google Places API当前不支持从Google API Console生成的iOS密钥。目前仅支持服务器和浏览器密钥。

...if you would like to request this support, please file a Places API - Feature Request .." ...如果您想请求此支持,请提交Places API-功能请求 ..”

from this answer: https://stackoverflow.com/a/14744513/1702413 从这个答案: https : //stackoverflow.com/a/14744513/1702413

You can use Google Maps JavaScript API v3 ( Places Library of the Google Maps API v3 ) 您可以使用Google Maps JavaScript API v3( Google Maps API v3的位置库

or.. 要么..

is working from iOS.. if you are using an HTML5 mobile application framework like Sencha Touch.. you can check this tutorial Create a Location-Aware Site with Sencha Touch 正在从iOS上运行..如果您使用的是诸如Sencha Touch的HTML5移动应用程序框架,则可以查看本教程, 以使用Sencha Touch创建位置感知站点

UPD UPD

is working if you are using Key for browser apps (with referers) from API console 如果您正在使用API​​控制台中Key for browser apps (with referers)则可以正常工作

for example (I'm using AFNetorking): 例如(我正在使用AFNetorking):

        NSURL *url = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Sydney&sensor=true&key=yourKEYforBrowser"];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

            NSArray *result = [JSON valueForKeyPath:@"results"];
            NSLog(@"Google Resp: %@", result);

        } 
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
                                             {
                                                 NSLog(@"error");
                                             }
                                             ];

        [operation start];

This is very easy to get Google Places API key: 这很容易获得Google Places API密钥:

Where you create "Android / iOS" keys, there is a more button for creating Browser key. 在创建“ Android / iOS”键的地方,还有一个用于创建浏览器键的按钮。

Simply press "Create new Browser Key" and click on "Create" button. 只需按“创建新的浏览器密钥”,然后单击“创建”按钮。

"BUT Leave the body empty" “但是把身体空着”

For more details similar question , @Moe explaind the complete flow with screenshots. 有关类似问题的更多详细信息,@Moe用屏幕截图说明了完整流程。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM