Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting status "REQUEST_DENIED" after fetching data from google places API

I have done that

    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 am getting this-

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

**Is there any problem with API Key i have wrote API key given by google map. Is there any problem with api key or what please tell me here is the link of google api

like image 333
Prabhjot Singh Gogana Avatar asked Sep 05 '12 05:09

Prabhjot Singh Gogana


People also ask

Why Google Places API is not working?

It looks like you try to use Web Service, not Places API for Android. In this case you cannot apply an API key with Android app restriction. Web Service requires a different API key. You can generate the new one, the only restriction that you can use with web services is by IP.

How do I get data from Google Maps places API?

Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.

How do I use Google Places Autocomplete API?

Ensure that the API key(s) used for all Place Autocomplete and Place Details requests within a session belong to the same Cloud Console project. Be sure to pass a unique session token for each new session. Using the same token for more than one session will result in each request being billed individually.


1 Answers

Although this has been answered, I think the community could do better in explaining what ACTUALLY needs to be done in order to get this working.

I was tearing my hair out about this, it just didn't make sense to me.. I was making an iOS/Android App, so I made an iOS/Android Key... Wrong.

With Google's Places API, your bundle identifier isn't even considered.

What you really want to do is this: (I'm using the new User Interface)

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

Select your Project Name, then go into API's & Auth > APIs

Make sure you have Places API Turned on. This is the only thing that needs to be turned on for Places-API to work. enter image description here

2. Go into Credentials

Click CREATE NEW KEY under Public API Access enter image description here

3. Select BROWSER KEY enter image description here

4. Click Create, Nothing Else

Leave the HTTP Refer box empty.

enter image description here

5. Use the Key Generated here

This key will allow ANY user from any device access to the API via your Developer login. You can try it out here: (Be sure to replace YOUR_KEY_HERE with your generated Key)

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

6. Enjoy

Now you can use that URL above in your Android/iOS device.

like image 103
Moe Avatar answered Oct 08 '22 08:10

Moe