我已經使用我的項目的Google控制檯生成了一個API密鑰。然後,正如他們在文檔中提到的那樣,我在的didFinishLaunchingWithOptions
方法中添加了密鑰。下面的代碼:無法使用生成的密鑰訪問Google Places API
[GMSServices provideAPIKey:@"{MY_API_KEY}"];
然後我用下面的代碼從我的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];
而且我得到如下回應:
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key.",
"predictions" : [],
"status" : "REQUEST_DENIED"
}
我在這裏做錯了什麼?如何糾正這一點?
是的,它在那裏 –