【问题标题】:Google Places API Response status "Request_Denied"Google Places API 响应状态“Request_Denied”
【发布时间】:2013-07-15 14:25:51
【问题描述】:

我正在为我的 iOS 应用程序使用 Google Places API。我已启用 Google Maps Android API v2,来自 API 控制台的 Places API。在 API 访问部分创建 iOS 密钥。我正在使用以下代码向 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]];

但我在 JSON 响应中得到关注

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

我重新生成了不能正常工作的新密钥。有人可以弄清楚我在这里做错了什么。

【问题讨论】:

  • API控制台中是否启用了具体项目?
  • 看看这个。 link
  • 另外,如果您想要餐馆,最好使用 types=restaurant 而不是关键字。这两者各有不同。
  • @Stavash 我刚刚在 API 控制台中创建了一个项目,并使用我的项目的包标识符生成了 iOS 密钥。我还需要做些什么吗?我怎么知道特定项目是否已启用。我将不胜感激任何帮助.. 3 小时后我有点卡住了

标签: iphone ios google-maps google-places-api


【解决方案1】:

“...Google Places API 当前不支持从 Google API 控制台生成的 iOS 密钥。目前仅支持服务器和浏览器密钥..”

...如果您想请求此支持,请提交Places API - Feature Request..”

来自这个答案:https://stackoverflow.com/a/14744513/1702413

您可以使用 Google Maps JavaScript API v3 (Places Library of the Google Maps API v3)

或者..

在 iOS 上工作。如果您使用的是像 Sencha Touch 这样的 HTML5 移动应用程序框架。您可以查看本教程 Create a Location-Aware Site with Sencha Touch

UPD

如果您从 API 控制台使用 Key for browser apps (with referers),则可以正常工作

例如(我正在使用 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];

【讨论】:

  • 那么我如何在 iOS 应用程序中获取附近的地点以及地址、评级、联系电话、图标等所有详细信息?
  • 刚刚尝试过...如果您使用的是“浏览器应用程序密钥(带有引用者)”,则可以正常工作
  • 不要尝试直接从您的应用程序调用谷歌服务器,因为服务器密钥很容易泄露。
  • @chings228 真的吗? :) 这个“公钥”还能做什么? :) 你“调用”谷歌服务器的方法是什么?
【解决方案2】:

这很容易获得 Google Places API 密钥:

在您创建“Android / iOS”键的地方,有一个用于创建浏览器键的更多按钮。

只需按“创建新的浏览器密钥”并单击“创建”按钮。

“但是让身体空着”

更多详情similar question,@Moe 用截图解释了完整的流程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-22
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    相关资源
    最近更新 更多