Reputation: 8065
I have generated an API Key using google's console for my project. Then as they have mentioned in their documentation, I have added the key in my applications AppDelegate
in the didFinishLaunchingWithOptions
method. The following code:
[GMSServices provideAPIKey:@"{MY_API_KEY}"];
Then I used the following code to send a Google Places Auto complete request from inside my ViewController:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&sensor=false&key={MY_API_KEY}",searchString]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:120];
placesListConnection = [NSURLConnection connectionWithRequest:request delegate:self];
And I am getting the following response:
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key.",
"predictions" : [],
"status" : "REQUEST_DENIED"
}
What am I doing wrong here? How to rectify this?
Upvotes: 1
Views: 390
Reputation: 8065
Finally solved the issue. Instead of using API_KEY
for IOS, i created an API_KEY
for web that doesn't need a referrer and then sent the request using that key. Now it is working perfectly.
Upvotes: 1
Reputation: 3616
Have you checked Developers Console? Is Places API enabled under APIs & auth > APIs?
Upvotes: 0