I am trying to post images and videos to twitter with yFrog through my application, but nothing seems to even happen when I make the request... can anyone see what I am doing wrong or point me in the right direction? thank you
-(IBAction)yFrogToTwitter
{
// create the URL
//used to render bigger images videos
//NSURL *postURL = [NSURL URLWithString:@"http://render.imageshack.us/renderapi/start"];
//below is used to directly upload to twitter
NSURL *postURL = [NSURL URLWithString:@"http://yfrog.com/api/uploadAndPost"];
// create the connection
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:postURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
// change type to POST (default is GET)
[postRequest setHTTPMethod:@"POST"];
// create data
NSMutableData *postBody = [NSMutableData data];
//NSString *media = PickedImage.image;
NSString *username = twitterEngine.username;
NSString *password = twitterEngine.password;
NSString *message = TweetBody.text;
NSString *source = @"ThemeCatcher";
NSString *api_key= kYFrogKey;
// just some random text that will never occur in the body
NSString *stringBoundary = @"0xKhTmLbOuNdArY---This_Is_ThE_BoUnDaRyy---pqo";
// header value
NSString *headerBoundary = [NSString stringWithFormat:@"multipart/form-data;
boundary=%@",stringBoundary];
// set header
[postRequest addValue:headerBoundary forHTTPHeaderField:@"Content-Type"];
// username part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data;
name=\"username\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[username dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// password part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data;
name=\"password\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[password dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// api_key
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data;
name=\"key\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[api_key dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// message part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data;
name=\"message\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[message dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// source part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data;
name=\"source\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[source dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// media part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Disposition: form-data; name=\"media\";
filename=\"fish.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/jpeg\r\n"
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Transfer-Encoding: binary\r\n\r\n"
dataUsingEncoding:NSUTF8StringEncoding]];
NSData *imageData = UIImagePNGRepresentation(PickedImage.image);
// add Image to body
[postBody appendData:imageData];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// final boundary
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
// add body to post
[postRequest setHTTPBody:postBody];
// pointers to some necessary objects
//NSURLResponse* response;
//NSError* error;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:postRequest
delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
}