Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Have you checked Developers Console? Is Places API enabled under APIs & auth > APIs?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top