1

iOS アプリから Reddit に送信しようとしています。私は正常にログインでき、 経由で保存した modhash と Cookie が返されますNSUserDefaults

問題は、投稿に modhash を含めてセッション Cookie を設定したにもかかわらず、データを投稿すると、応答として「USER_REQUIRED」が返されることです。アプリのデリゲートに次のものも含めました。

[[NSHTTPCookieStorage sharedHTTPCookieStorage]
    setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

しかし、それでもうまくいきません。これが私のコードです:

-(void) post {

    NSString *modhash2 = [[NSUserDefaults standardUserDefaults]  
        objectForKey:@"modhash"];

    NSString *urlString = [NSString 
        stringWithFormat:@"https://ssl.reddit.com/api/submit"];
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

    NSString *contentType = [NSString stringWithFormat:@"application/x-www-form-urlencoded;"];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
    [request addValue:redditCookie forHTTPHeaderField:@"Cookie"];


    [request setHTTPMethod:@"POST"];
    NSString *httpBody = [NSString stringWithFormat
        :@" ?uh=%@&kind=link&url=%@&sr=%@&title=%@&r=%@&api_type=json",
        modhash2,
        @"www.google.com",
        @"test",
        @"Google.com",
        @"test"];


    [request setHTTPBody:[httpBody dataUsingEncoding:NSASCIIStringEncoding]];

    NSURLResponse* response;
    NSError* error = nil;
    NSData* result = [NSURLConnection
        sendSynchronousRequest:request
        returningResponse:&response
        error:&error];

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

    NSDictionary *responseJSON = [json valueForKey:@"json"];
    NSLog(@"RETURN: %@",responseJSON);
}

何か案は?

4

0 に答える 0