Google API密钥无效 - iOS

时间:2013-05-03 05:26:24

标签: ios xcode google-api google-places-api

我已经尝试了一切。我正在尝试使用google place API请求一些地方。但是,我收到请求被拒绝。 即使我在我的iOS代码中使用它,我的浏览器应用程序密钥也能正常工作,即:

- (IBAction)google:(id)sender {

        NSError *error;

    NSString *lookUpString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=-37.849968,145.046310&radius=500&types=food&sensor=true&key=AIzaSyCbG9UrsqSXytrF7h9nRG66erS-bhCM9j0"];

    lookUpString = [lookUpString stringByReplacingOccurrencesOfString:@" " withString:@"+"];

    NSData *jsonResponse = [NSData dataWithContentsOfURL:[NSURL URLWithString:lookUpString]];
    NSString *newStr = [[NSString alloc]initWithData:jsonResponse encoding:NSUTF8StringEncoding];
    NSLog(@"locationArray count: %@", newStr);

    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonResponse options:kNilOptions error:&error];

    NSArray *locationArray = [[jsonDict valueForKey:@"results"]valueForKey:@"formatted_address"];

    int total = locationArray.count;
    NSLog(@"locationArray count: %d", locationArray.count);
}

我到处搜寻,找不到任何帮助。

Ps1:这是我真正的钥匙(仅供测试)。

Ps2:我的bundle根据xCode标识:dsg.JSONTest(这样可以吗?)

感谢您的所有帮助

0 个答案:

没有答案