我正在编写iOS中集成到Instagram的应用程序。使用类似API调用时,我会从Instagram获得HTTP错误400。其他API调用正常。这是我发布请求
的代码的一部分{
NSDictionary* params = [NSDictionary dictionaryWithObject:_accessToken forKey:@"access_token"];
NSString* path = [NSString stringWithFormat:kUserLikeEndPoint, medID];
NSURL *url = [NSURL URLWithString:path relativeToURL:[NSURL URLWithString:kInstagramBaseURLString]];
NSMutableArray *mutableParameterComponents = [NSMutableArray array];
for (NSString *key in [params allKeys]) {
NSString *component = [NSString stringWithFormat:@"%@=%@", [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[[params valueForKey:key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[mutableParameterComponents addObject:component];
}
url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", [mutableParameterComponents componentsJoinedByString:@"&"]]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:defaultHeaders];
likeInstagramConnection = [NSURLConnection connectionWithRequest:request delegate:self];
}
在此连接期间,我得到以下错误
Error Domain=HTTP Code=400 "HTTP Error" UserInfo=0xd9571b0 {NSLocalizedDescription=HTTP Error} desc <NSHTTPURLResponse: 0xd9574a0> { URL: https://api.instagram.com/v1/media/632580883841234624_257450972/likes?access_token=ACCESS_TOKEN_GOES_HERE } {
status code: 400, headers {
Connection = "keep-alive";
"Content-Language" = en;
"Content-Length" = 92;
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 28 Jan 2014 07:17:52 GMT";
Server = nginx;
"Set-Cookie" = "csrftoken=5eaa89da550811f9d62d5c15525ceebf; expires=Tue, 27-Jan-2015 07:17:52 GMT; Max-Age=31449600; Path=/, ccode=US; Path=/";
Vary = "Cookie, Accept-Language";
"X-Ratelimit-Limit" = 5000;
"X-Ratelimit-Remaining" = 4997;
}
}
可能是过期的访问令牌。我知道在Python中,我在API调用异常中获得了此错误代码,我看不出为什么它们会使语言之间的状态代码不同。希望您能朝正确的方向。