Upload picture from ios using Oauth


#1

Hi, i am trying to upload the image from my iOS application using Oauth and the following error occur
{“error”:“Could not authenticate with OAuth.”,“request”:"/1/statuses/update_with_media.json"}

simple tweet is working but not with image.


#2

I think, require media key


#3

@HovServices here is the request

NSString*oauth_ehader = [super oAuthHeaderForMethod:@"POST"
andUrl:kDMPostStatusWithMediaURL
andParams:params
andTokenSecret:self.oauth_token_secret];

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:kDMPostStatusWithMediaURL]
                                                       cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                   timeoutInterval:7.0f];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]

forHTTPHeaderField:@“Content-Type”];

NSMutableData *myRequestData = [NSMutableData data];


// media part
[myRequestData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:[@"   Content-Disposition: form-data; name=\"media_data[]\"; filename=\"1.png\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:[@"Content-Type: application/octet-stream\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:[[NSString stringWithString:[UIImageJPEGRepresentation(imageData, 1.0) base64EncodedString]] dataUsingEncoding:NSUTF8StringEncoding]];

//status part
[myRequestData appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:[@"Content-Disposition: form-data; name=\"status\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:[@"Honeymoon uploads image\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

[myRequestData appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];    // add it to body

    [request addValue:oauth_ehader forHTTPHeaderField:@"Authorization"];

[request setHTTPBody:myRequestData];



NSHTTPURLResponse* response = nil;
NSError *error = nil;

NSData *responseData = [NSURLConnection sendSynchronousRequest:request
                                             returningResponse:&response
                                                         error:&error];

NSString *responseString = [[NSString alloc] initWithData:responseData
                                                 encoding:NSUTF8StringEncoding];