Google API (YouTube search): Bad network response

382 views Asked by At

I'm getting following error while fetching videos by keywords from youtube from my iOS application:

Error Domain=JSONModelErrorDomain Code=2 "Bad network response. Probably the JSON URL is unreachable." UserInfo=0x79d86730 {NSLocalizedDescription=Bad network response. Probably the JSON URL is unreachable.

Here is my code:

NSString* searchCall = [NSString stringWithFormat:@"https://www.googleapis.com/youtube/v3/search?part=snippet&q=cats&type=video&videoCaption=closedCaption&key=AIzaSyDmq5TM_NJrpNuDoMcnnWjdg8lITTyzbDM"];

[JSONHTTPClient getJSONFromURLWithString: searchCall
                              completion:^(NSDictionary *json, JSONModelError *err) {
                                  NSLog(@"%@", err);
                              }];

Please help me in resolving the issue.

2

There are 2 answers

1
PoseLab On

There is some problem with the api key, update it and it will work:

"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.",

0
slavik On

Ok, for now I've resolved my problem by removing all bundleIds that can use API key ("Google Developer Console" -> "APIs & auth" -> "Credentials" -> button "Edit allowed iOS applications"), so after that I've see line "iOS applications: Any application allowed".