1

Can somebody help me with this? I am using an NSURL connection for GET and POST methods. The reddit api is found here: http://www.reddit.com/dev/api#POST_api_subscribe

I am specifically confused with what the ('sr', 'sr_name') parameter is. Is it an array of some sort? Or do I have to pass either of 'sr' or 'sr_name'?

My current code:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.reddit.com/api/subscribe"]]];
    [request setHTTPMethod:@"POST"];


        request.HTTPBody = [[NSString stringWithFormat:@"api_type=json&action=%@&uh=%@&sr=%@", @"sub", modhashString, SubredditTitle] dataUsingEncoding:NSASCIIStringEncoding];


    NSURLResponse *response;

    NSError *error;

    NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    if (!error) {


        NSDictionary *json = [NSJSONSerialization
                              JSONObjectWithData:POSTReply
                              options:NSJSONReadingMutableContainers
                              error:nil];

        NSLog(@"%@", json);

        NSMutableArray *temp = [[json objectForKey:@"json"] objectForKey:@"errors"];

        if ([temp count] > 0){

            for (int i = 0; i<[temp count]; i++) {


                NSArray *temp2 = [[NSArray alloc] init];
                temp2 = [temp objectAtIndex:i];

                NSLog(@"Contains errors %@", temp2);

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[temp2 objectAtIndex:1] message:nil delegate:self cancelButtonTitle:@":/" otherButtonTitles:nil, nil];

                [alert show];

            }
        }
        else{


        }
John Sheehan
  • 77,456
  • 30
  • 160
  • 194

0 Answers0