2015-02-03 3 views
9

Mam witrynę hostowaną na platformie Azure, gdzie są blokowane połączenia z interfejsem API Google UrlShortner. Otrzymuję komunikat o błędzie:Google UrlShortener "ipRefererBlocked"

{ 
"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." 
} 
} 

Interfejs API działa poprawnie działa lokalnie i dodałem adres IP do poświadczeń projektu interfejsu API w konsoli programisty. To wydaje się być problemem z Azure, ale nie widzę, gdzie ktoś ma odpowiedź.

Wszelkie sugestie będą świetne!

Odpowiedz

1

Nigdy nie udało mi się rozwiązać tego problemu za pomocą statycznego adresu IP. Obejście było małe. Ich api działało bezbłędnie.

+0

Człowieku, czy możesz wyjaśnić więcej? Mam ten sam błąd i nie mogę tego naprawić :( – Peter

0

Tak, używaj małego adresu URL, ale nie interfejsu API. Nigdy nie byłem w stanie uruchomić ich API.

+ (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; 
} 
Powiązane problemy