Update_with_media Twitter api

时间:2012-06-01 06:29:17

标签: iphone twitter

当我第一次在Twitter Api上玩时,我在使用NSMutableURLRequest为update_with_media twitter构建主体时遇到了问题。在这里我不使用MGTwitterEngine。

注册,updated_status等工作正常。

NSString *postUrl = @"https://api.twitter.com/1/statuses/update_with_media.json";

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:postUrl]];

    NSString *iString =@"hi test url";

   // NSData *imageData = UIImagePNGRepresentation(iImage);

//    NSMutableDictionary *postInfo = [NSMutableDictionary
//                                     dictionaryWithObject:iString
//                                     forKey:@"status"];

    NSMutableDictionary *postInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:iImageData,@"media[]",iString,@"status",nil];

    NSString *postBodyString = [NSString stringWithFormat:@"status=%@", [iString encodedURLParameterString]];

    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[postBodyString dataUsingEncoding:NSUTF8StringEncoding]];
    [request setValue:[self oAuthHeaderForMethod:@"POST"
                                          andUrl:postUrl
                                       andParams:postInfo] forHTTPHeaderField:@"Authorization"];

    NSHTTPURLResponse *response;
    NSError *error = nil;

    [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    if (error)
    {
        //        NSLog(@"Error from NSURLConnection: %@", error);

    }
    NSLog(@"Status posted. HTTP result code: %d", [response statusCode]);

我尝试发送请求我收到此错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0xedf3ec0'
*** First throw call stack:
(0x22c9062 0x26a5d0a 0x22cacfd 0x222ff10 0x222fcf2 0x21d1d78 0x21dcd8d 0x95622f 0x95616f 0x95611a 0xe7fdd 0xe9b73 0x936276 0x9361e7 0x9391c259 0x9391c0de)

0 个答案:

没有答案
相关问题