IPhone : Can't Post request using instagram API in IOS

on Saturday, March 28, 2015

I want to use the Instagram API, and I downloaded this project from link : https://www.cocoacontrols.com/controls/instagramkit, But I can't Post a Request to the server, it always gets the following error :



Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: forbidden (403)" UserInfo=0x79eb1330 {NSErrorFailingURLKey=https://api.instagram.com/.../950394368622277294.../likes, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7a12c8c0> { URL: https://api.instagram.com/.../950394368622277294.../likes } { status code: 403, headers {
"Cache-Control" = "private, no-cache, no-store, must-revalidate";
Connection = "keep-alive";
"Content-Language" = en;
"Content-Length" = 143;
"Content-Type" = "application/json";
Date = "Sat, 28 Mar 2015 10:07:53 GMT";
Expires = "Sat, 01 Jan 2000 00:00:00 GMT";
Pragma = "no-cache";
Server = nginx;
Vary = "Accept-Language, Cookie";
"X-Instagram-Ssl-Wifi" = False;
} }, NSLocalizedDescription=Request failed: forbidden (403)}


when calling this method:



- (void)postPath:(NSString *)path
parameters:(NSDictionary *)parameters
responseModel:(Class)modelClass
success:(void (^)(NSDictionary *responseObject))success
failure:(void (^)(NSError* error, NSInteger statusCode))failure
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameters];
if (self.accessToken) {
// NSString *p = [NSString stringWithFormat:@"access_token=%@", self.accessToken];
NSString *percentageEscapedPath = [self.accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[params setObject:percentageEscapedPath forKey:kKeyAccessToken];
// [params setObject:self.appClientID forKey:kKeyClientID];
}
else
[params setObject:self.appClientID forKey:kKeyClientID];

[self.httpManager POST:path
parameters:params
#if (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
success:^(AFHTTPRequestOperation *operation, id responseObject) {
#else
success:^(NSURLSessionDataTask *task, id responseObject) {
#endif
NSDictionary *responseDictionary = (NSDictionary *)responseObject;
success(responseDictionary);
}
#if (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(error,[[operation response] statusCode]);
#else
failure:^(NSURLSessionDataTask *task, NSError *error) {
failure(error,((NSHTTPURLResponse*)[task response]).statusCode);
#endif
}];


}

0 comments:

Post a Comment