1
我想使用谷歌Places API的,但我不斷收到一個REQUEST_DENIED。我進入了Google API控制檯,並開啓了Google Places API。我的代碼是這樣的:谷歌將REQUEST_DENIED恐怖
NSString *searchString = [NSString stringWithFormat:@"Beirut"];
NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=%@&sensor=true&key=%@!",searchString, kGOOGLE_API_KEY];
NSURL *requestURL = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:(requestURL)];
//response
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSDictionary *locationResults = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
NSLog(@"%@",locationResults);
我翻了一番檢查,我使用了正確的API密鑰和我收到此輸出:
{
"debug_info" = (
);
"html_attributions" = (
);
results = (
);
status = "REQUEST_DENIED";
}
我再次進入到谷歌API控制檯,點擊「嘗試「通過谷歌地方開/關開關旁邊的」問號「信息按鈕,我直接到另一個具有相同輸出的標籤。我該如何解決這個問題?
編輯:多類型添加到URL會導致錯誤
NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%@&types=food|bar&sensor=true&key=%@", currentLocation.coordinate.latitude, currentLocation.coordinate.longitude, [NSString stringWithFormat:@"%i", 1000], kGOOGLE_API_KEY];
*臉手掌*我的壞..現在的工作,但是當我包括到類型,如食品|在地址欄,它停止工作(應用程序崩潰)在NSDictionary部分。任何暗示爲什麼會發生這種情況? – HusseinB
發佈代碼和錯誤的NSDictionary部分。如果回覆爲零,則可能會崩潰。 – Yan
請參考上面的代碼。是的,它返回零。什麼可能導致這個? – HusseinB