使用AFNetwork调用post API时出错

时间:2015-06-29 06:05:44

标签: ios afnetworking instagram

我正在尝试使用AFNetworking在Instagram上调用POST API,我的代码是:

void (^mySuccessBlock)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {

    NSDictionary* userInfo = (NSDictionary*) responseObject;

    if (block != nil) {
        block(userInfo, nil);
    }
};

void (^failureBlock)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Request Error: %@", error);

    if (block != nil) {
        block(nil, error);
    }
};

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

manager.requestSerializer = [AFJSONRequestSerializer serializer];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSMutableDictionary *param=[[NSMutableDictionary alloc]init];
NSString * token =[defaults objectForKey:ACCESS_TOKEN];
[param setValue:token forKey:@"access_token"];

NSString *url=[NSString stringWithFormat:@"https://api.instagram.com/v1/media/%@/likes" , globalMediaId];
[manager POST:url parameters:param success:mySuccessBlock failure:failureBlock ];

但是我收到了这个错误:

  

请求错误:错误域= com.alamofire.error.serialization.response   代码= -1011“请求失败:错误请求(400)”UserInfo = 0x7fb4c9698e00   {com.alamofire.serialization.response.error.response = {URL:   https://api.instagram.com/v1/media/853150485752748330_1509614005/likes   } {状态代码:400,headers {       “Cache-Control”=“私有,无缓存,无存储,必须重新验证”;       Connection =“keep-alive”;       “Content-Language”= en;       “内容长度”= 114;       “Content-Type”=“application / json; charset = utf-8”;       Date =“Mon,29 Jun 2015 05:55:33 GMT”;       Expires =“周六,2000年1月1日00:00:00 GMT”;       Pragma =“no-cache”;       “Set-Cookie”=“csrftoken = f4b5426f69b154c60e6785ba52100a09; expires = Mon,27-Jun-2016 05:55:33 GMT; Max-Age = 31449600; Path = /”;       Vary =“Cookie,Accept-Language”; ,NSErrorFailingURLKey = https://api.instagram.com/v1/media/853150485752748330_1509614005/likes,   com.alamofire.serialization.response.error.data =< 7b226d65 7461223a   7b226572 726f725f 74797065 223a224f 41757468 50617261 6d657465   72457863 65707469 6f6e222c 22636f64 65223a34 30302c22 6572726f   725f6d65 73736167 65223a22 4d697373 696e6720 61636365 73735f74   6f6b656e 2055524c 20706172 616d6574 65722e22 7d7d>,   NSLocalizedDescription =请求失败:错误请求(400)}

有谁知道我为什么会这样做?

0 个答案:

没有答案