2014-05-04 75 views
1

我已經使用我的項目的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" 
} 

我在這裏做錯了什麼?如何糾正這一點?

回答

1

終於解決了這個問題。我沒有爲IOS使用API_KEY,而是爲網絡創建了一個API_KEY,它不需要引用鏈接,然後使用該密鑰發送請求。現在它工作完美。

0

您是否檢查了Developers Console?在API & auth> APIs下啓用Places API嗎?

+0

是的,它在那裏 –

相關問題