我在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的一个问题,但我不知道哪里有人有答案。
任何建议都会很棒!
答案 0 :(得分:1)
即使使用静态IP,我也无法解决这个问题。解决方法是tinyUrl。他们的api完美无缺。
答案 1 :(得分: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;
}