在Objective-C中调用Instagram API时获取错误400

问题描述 投票:0回答:1

我正在iOS中编写一个集成到Instagram的应用程序。我在使用Like API调用时从Instagram获得了Http Error 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;
    }
}
ios objective-c api instagram social-media-like
1个回答
0
投票

可能是过期的访问令牌。我知道在python中我在API调用异常中收到此错误代码,我不明白为什么他们会使语言之间的状态代码不同。希望能让你朝着正确的方向前进。

© www.soinside.com 2019 - 2024. All rights reserved.