I am having a small Reddit API problem here. I am trying to follow the reddit api, as outlined here:
https://github.com/reddit/reddit/wiki/API
Logging in using a simple NSMutableURLRequest is not a problem:
NSString *user = [[NSString alloc]initWithString:[userFld text]];
NSString *passwd = [[NSString alloc]initWithString:[passwordFld text]];
NSString *urlString = [NSString stringWithFormat:@"http://www.reddit.com/api/login/username/?user=%@&passwd=%@",
[user stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[passwd stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Which gives me a result from which I extract the user mod-hash:
4029916%2C2010-04-30T22%3A51%3A52%2C1243925043100000000000000000000000000000
Next I am trying to post, using:
NSString *redditUrlString = [NSString stringWithFormat:
@"http://www.reddit.com/api/submit/?uh=%@&kind=link&url=%@&sr=%@&title=%@&r=%@&api_type=json",
[appDelegate globalUhString],
@"www.google.com",
@"funny",
@"Google.com",
@"funny"];
NSURL *url = [NSURL URLWithString:redditUrlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
However, when I extract the JSON response form the data received from this connection, I always receive the error below no matter what I use as the mod-hash:
[".error.USER_REQUIRED"]
Can someone explain what I have done incorrectly/how I can fix it?