Getting the status "REQUEST_DENIED" after receiving data from google places API

I did it

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

// But I get it -

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

** Are there any problems with the API Key, I wrote the API key specified in the google map. Are there any problems with the api key or what tell me, here is the google api link

+5
source share
6 answers

In the API console for this key, you must enable the Static Maps API and the Places API. Open the API console and enable access to the API. There is a limit on Courtesy: 1,000 requests / day, after which you may need to enable billing.

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

+2
source

, , , , , .

, .. iOS/Android, iOS/Android Key... .

API Google .

, : ( )

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

, API API Auth >

, API "". , Places-API. enter image description here

2.

CREATE NEW KEY Public API Access enter image description here

3. BROWSER KEY enter image description here

4. "", " "

HTTP Refer.

enter image description here

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.

URL Android/iOS.

+20
+4

Josh. , IOS .

+2

try the following: -

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

Read the next part and follow the steps to get the key.

Authentication

The Google Places API uses an API key to identify your application. API keys are managed through the Google API console. You will need your own API key before you can start using the API. To activate the Places API and create your own key:

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.
+1
source

I get this code.

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

    });
});
0
source

All Articles