【问题标题】:Getting status "REQUEST_DENIED" after fetching data from google places API从 Google Places API 获取数据后获取状态“REQUEST_DENIED”
【发布时间】:2012-08-29 19:10:59
【问题描述】:

我已经做到了

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/search/json?location=30.722322,76.76126&radius=500&types=food&sensor=true&key=any_apiKey"]];

    NSURLResponse *response;
    NSError *error;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *strResponse = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",strResponse);

    SBJSON *sbJason = [[SBJSON alloc] init];
    NSMutableDictionary *getPlaceList = [sbJason objectWithString:strResponse]; 

// 但我得到了这个-

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

**API 密钥有什么问题吗?我写了谷歌地图给出的 API 密钥。 api密钥有什么问题吗?或者请告诉我这里是link of google api

【问题讨论】:

  • 您是否真的将“any_apikey”作为您的 api 密钥传递?
  • 不不,这不是我真正的 api 密钥。我有 google 提供的不同 api 密钥
  • 好的,很好:) 只是想检查一下
  • 你在PC浏览器上试过这个网址吗?
  • REQUEST_DENIED 指向无效密钥。仔细检查密钥以及如何从places API提供密钥

标签: iphone objective-c ios google-maps google-maps-api-3


【解决方案1】:

尽管已经回答了这个问题,但我认为社区可以更好地解释为了使其正常工作实际需要做什么。

我对此感到非常恼火,这对我来说毫无意义。我正在制作一个 iOS/Android 应用程序,所以我制作了一个 iOS/Android 密钥... 错误。

使用 Google 的 Places API,甚至不会考虑您的包标识符。

你真正想做的是: (我正在使用新的用户界面)

1.登录https://cloud.google.com/console#/project

选择您的项目名称,然后进入 API's & Auth > APIs

确保您已开启 Places API。这是唯一需要打开 Places-API 才能工作的东西。

2。进入凭据

点击 Public API Access 下的 CREATE NEW KEY

3.选择浏览器密钥

4.点击创建,别无其他

将 HTTP 引用框留空。

5.使用此处生成的密钥

此密钥将允许来自任何设备的任何用户通过您的开发者登录访问 API。 您可以在这里尝试一下:(请务必将 YOUR_KEY_HERE 替换为您生成的密钥)

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Food%20Sh&sensor=false&radius=500&location=0,0&key=YOUR_KEY_HERE

6.享受

现在您可以在 Android/iOS 设备中使用上述 URL。

【讨论】:

  • 就是这样。第 4 步(将 HTTP 引用框留空。)对我有用。
  • 这是最好的答案。非常感谢。
  • 虽然这可能感觉像是一个笨拙的答案,但它是唯一的选择。 Google Places API 目前不支持 Android 或 IOS 密钥.... SMH 你可以在 google code.google.com/p/gmaps-api-issues/issues/detail?id=4896看到官方请求
  • 我很高兴。谢谢。
  • 获取“此服务需要 API 密钥。”这个错误 ios 。我正在使用浏览器键发出 POST 请求。请帮助我。
【解决方案2】:

尝试使用 BROWSER 应用程序密钥,而不是 iOS 密钥。你可以在这里找到它:

https://code.google.com/apis/console/

然后按左侧的“API Access”

【讨论】:

  • 我试图为 Android 应用程序使用密钥,但正如 @CaptainQuality 所说,使用浏览器应用程序密钥对我有用,并且不创建您的移动操作系统特定密钥。我不知道为什么这需要让谷歌如此困惑。
【解决方案3】:

Static Maps API 和 Places API 都需要在 API 控制台中为该密钥启用。打开 API 控制台并启用对 Places API 的访问。有一个礼貌限制:每天 1,000 个请求,之后您可能需要启用计费功能。

https://code.google.com/apis/console/

【讨论】:

  • 您好,如何在控制台中启用对 Places API 的访问。你能简要介绍一下步骤吗?
【解决方案4】:

只想支持 Josh 的解决方案。我花了几个小时弄清楚 IOS 密钥,几乎放弃了。

【讨论】:

    【解决方案5】:

    试试这个:-

    https://developers.google.com/places/documentation/

    阅读以下部分并继续执行获取密钥的步骤。

    身份验证

    Google Places API 使用 API 密钥来识别您的应用程序。 API 密钥通过 Google API 控制台进行管理。在开始使用 API 之前,您需要自己的 API 密钥。要激活 Places API 并创建您的密钥:

    Visit the APIs console at https://code.google.com/apis/console and log in with your Google Account.
    A default project called API Project is created for you when you first log in to the console. You can use the project, or create a new one by clicking the API Project button at the top of the window and selecting Create. Maps API for Business customers must use the API project created for them as part of their Places for Business purchase.
    Click the Services link from the left-hand menu.
    Click the Status switch next to the Places API entry. The switch slides to On.
    Click API access from the left navigation. Your key is listed in the Simple API Access section.
    

    【讨论】:

    • LOL ...我有那个 API 密钥 AIzaSyC6RgmTP5LoaS6oFSiOSu????????????但我出于安全目的显示 any_apiKey...
    • 您需要阅读整个文档并解决问题,因为在不知道 api 密钥的情况下,我们无法运行 url 并检查其中是否有问题。
    • 看到那个问题同样的问题,但找不到任何答案....stackoverflow.com/questions/9060563/… .....api 密钥没有问题,因为我可以获取@"http//maps. googleapis.com/maps/api/staticmap?center=New+York,NY&zoom=13&size=6‌​00x300&sensor=true&key=AIzaSyC6RgmTP5LoaS6oFSiOSu???????????????”那个 json ......我认为这是一个谷歌问题,或者可能有不同的方式
    • 检查:- REQUEST_DENIED 表示您的请求被拒绝,通常是因为缺少传感器参数。尝试将传感器值更改为 false,并尝试使用一些不同的坐标进行测试。
    • 尝试使用下面的 url 只需替换密钥 maps.googleapis.com/maps/api/place/search/… 从这里你就会知道 url 或 google api 是否有问题。
    【解决方案6】:

    我最终得到了这段代码。

    UIActivityIndicatorView *activity=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activity.center=self.view.center;
    [activity startAnimating];
    [self.view addSubview:activity];
    
    
    NSString *str=[[NSString alloc] init];
    str=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=%@&sensor=true&key=YOUR_BROWSER_KEY",searchQuery];
    NSMutableURLRequest *request1=[[NSMutableURLRequest alloc] init];
    NSURL *url= [[NSURL alloc] initWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [request1 setURL:url];
    [request1 setHTTPMethod:@"GET"];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
        NSError *requestError = nil;
        NSURLResponse *urlResponse = nil;
        NSData *response1 =
        [NSURLConnection sendSynchronousRequest:request1
                              returningResponse:&urlResponse error:&requestError];
    
    
        dispatch_async(dispatch_get_main_queue(), ^{
    
    
            if ([activity isAnimating]) {
                [activity startAnimating];
                [activity removeFromSuperview];
            }
            NSError* error;
            NSDictionary* json = [NSJSONSerialization JSONObjectWithData:response1
                                                                 options:kNilOptions
                                                                   error:&error];
    
            NSLog(@"%@",json);
    
            self.searchArray=[json objectForKey:@"results"];
            [self.tableView setDataSource:self];
            [self.tableView setDelegate:self];
            [self.tableView reloadData];
    
            [self showPins:self.searchArray];
    
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2013-07-15
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多