从Google Places API获取数据后获取状态“REQUEST_DENIED”

我已经这样做了

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键或什么请告诉我这里是谷歌API的链接

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

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

尽pipe已经得到了答复,但我认为社群可以在解释实际工作需要做些什么来做得更好。

我正在撕裂我的头发,这只是没有意义的..我正在做一个iOS / Android应用程序,所以我做了一个iOS / Android的密钥… 错了。

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

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

1.login到https://cloud.google.com/console#/project

select您的项目名称,然后进入API的&Auth> API

确保您已启用Places API。 这是Places-API需要启用的唯一工作。 在这里输入图像说明

2.进入凭证

点击Public API Access下的CREATE NEW KEY 在这里输入图像说明

3.selectBROWSER KEY 在这里输入图像说明

4.点击Create,Nothing Else

保留HTTP引用框为空。

在这里输入图像说明

5.使用此处生成的密钥

此密钥将允许任何设备的用户通过您的开发者login访问API。 你可以在这里试试:(一定要用你生成的密钥replaceYOUR_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。

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

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

然后按左侧的“API访问”

只是想第二个乔希的解决scheme。 我已经花了几个小时找出IOS密钥,几乎放弃了。

尝试这个:-

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

阅读下面的部分,并进行步骤获取密钥。

authentication

Google Places API使用API​​密钥来识别您的应用程序。 API密钥是通过Google API控制台pipe理的。 您需要自己的API密钥才能开始使用API​​。 要激活Places API并创build您的密钥:

 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. 

我结束了这个代码。

 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]; }); });