Kevin Schultz
Kevin Schultz

Reputation: 884

Google UrlShortener "ipRefererBlocked"

I have a site hosted on Azure where the calls to the Google UrlShortner API are being blocked. I receive the error:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "ipRefererBlocked",
    "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.",
    "extendedHelp": "https://console.developers.google.com"
   }
  ],
  "code": 403,
  "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."
 }
}

The API works fine running locally and I have added the ip address to the API project credentials in the developer console. This appears to be an issue with Azure but I don't see where anyone has an answer.

Any suggestions would be great!

Upvotes: 9

Views: 1691

Answers (2)

ykonda
ykonda

Reputation: 527

Yes use tiny URL, but not their API. I was never able to get their API to work.

+ (void) shortenLink:(NSString*) link andPerformBlock:(void (^)(NSString*, NSError*))block {
    NSURLRequest* shortenedLinkRequest = [LinkShortener createTinyURLShortenerRequest:link];

    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:shortenedLinkRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        NSString*shortenedLink = @"";
        UIAlertView* alert = nil;
        if ([data length] > 0 && error == nil) {
            NSString* shortenedLink = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        }
        if (block) {
            block(shortenedLink, error);
        }
   }
 }

+ (NSURLRequest*) createTinyURLShortenerRequest:(NSString*) link {
    NSString* escapedLink = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];;
    NSString* tinyURLShortenerURL = [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@", escapedLink];
    NSURL* tinyURLShortenerUrl = [NSURL URLWithString:tinyURLShortenerURL];
    NSMutableURLRequest* shortenedLinkRequest = [NSMutableURLRequest requestWithURL:tinyURLShortenerUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:URL_SHORTENER_TIMEOUT];
    [shortenedLinkRequest setHTTPMethod:@"GET"];
    return shortenedLinkRequest;
}

Upvotes: 0

Kevin Schultz
Kevin Schultz

Reputation: 884

I was never able to get this resolved even using a static ip. Work around was tinyUrl. Their api worked flawlessly.

Upvotes: 1

Related Questions