Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I post images to reddit in iOS / Objective C?
    primarykey
    data
    text
    <p>I am trying to post an image to reddit; however, I only kind of know what I am doing. I am using objective c for my iphone app. </p> <p>Prior to the code listed below I obtain a modhash and cookie by logging in prior to the upload and use NSLog to determine that I truly am receiving them. Then I use a JSON Parser to separate them into separate variables.</p> <p>I was not sure what all of the POST argument values were supposed to be so I kind of guessed. The necessary arguments are uh, file, formid, header, ing_type, name, and sponsor.</p> <p>The documentation for reddit api is <a href="http://www.reddit.com/dev/api" rel="nofollow">http://www.reddit.com/dev/api</a> I believe that I want to use the POST /api/upload_sr_img method...</p> <pre><code>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=%@&amp;file=%@&amp;formid=''header=%@&amp;img_type=%@&amp;name=%@&amp;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:&amp;response error:&amp;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); </code></pre> <p>Could use any help I can get.</p> <p>Also, I was not sure if I needed to send a content-type or even what it would be. </p> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload