9

我有一个托管在 Azure 上的站点,其中阻止了对 Google UrlShortner API 的调用。我收到错误:

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

API 在本地运行良好,我已将 ip 地址添加到开发人员控制台中的 API 项目凭据中。这似乎是 Azure 的一个问题,但我看不到任何人有答案。

任何建议都会很棒!

4

2 回答 2

1

即使使用静态 IP,我也无法解决这个问题。解决方法是 tinyUrl。他们的 api 工作完美。

于 2015-02-05T22:31:14.967 回答
0

是的,使用小 URL,但不使用他们的 API。我永远无法让他们的 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;
}
于 2015-03-21T21:06:48.123 回答