我想張貼的圖片和視頻,通過我的應用程序使用yFrog到Twitter,但似乎沒有發生,甚至當我做出的請求......任何人都可以看到我在做什麼錯或點我在正確的方向?謝謝發佈至yFrog objc
-(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");
}
}
如果答案是錯誤的或者部分正確的,請將您的意見,用戶誰回答你的問題,使他們能夠改善自己的答案。謝謝。 –
謝謝。我會盡力在這裏做我的一部分,因爲我愛#1,並希望我做什麼或沒有通過這個冒犯任何人。我只是在做我認爲正確的事情,但是完全得到你們兩位的支持,並且將在未來的所有問題中牢記這一點。 – FreeAppl3
當然沒有 - 大家的幫助你,因此SO。 THX – bryanmac