2
我正在发表一个图像到reddit;然而,我只知道我在做什么。我使用目标c为我的iPhone应用程序。如何将图像发布到iOS/Objective C中的reddit?
在下面列出的代码之前,我通过在上传之前登录并使用NSLog来确定我真的在接收它们,从而获得了modhash和cookie。然后我使用JSON解析器将它们分离成单独的变量。
我不确定所有的POST参数值应该是什么,所以我有点猜测。必要的参数是呃,文件,formid,标题,ing_type,名称和赞助商。
为reddit的API的文档http://www.reddit.com/dev/api我相信,我想使用POST/API/upload_sr_img方法...
NSURL *url = [NSURL URLWithString:@"http://www.reddit.com/api/upload_sr_img"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *httpBody = [NSString stringWithFormat:@"?uh=%@&file=%@&formid=''header=%@&img_type=%@&name=%@&sponsor=%@",modhash,UIImagePNGRepresentation(self.memeImage.image),@"test",@"png",@"Drew",@"Drew'sApp"];
[request setHTTPBody:[httpBody dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse *response = NULL;
NSError *imgError = NULL;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&imgError];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:nil];
NSDictionary *responseJson = [json valueForKey:@"json"];
NSLog(@"response is: %@",response);
NSLog(@"imgError is: %@",imgError);
NSLog(@"result is: %@",result);
NSLog(@"json is: %@",json);
NSLog(@"responseJson is: %@",responseJson);
可以使用任何帮助我能。
此外,我不确定是否需要发送内容类型,甚至不需要。
感谢您的帮助。
Apple dev文档有详细的例子,介绍如何做到这一点。你读过这些吗? – Madbreaks 2013-02-27 21:20:28
那么这个问题更多的是试图理解Reddit的文档......我不知道应该在形成,标题,名称或赞助商。我也不知道是否需要发送内容类型和其他主要的http头信息。如果我应该寄给他们,我应该发送什么呢? – werdsackjon 2013-02-28 15:46:23