我需要将视频从我的 iphone 应用程序上传到 youtube,我有访问令牌表单 google oauth,但是在将视频上传到 youtube 时遇到问题,对于上传视频的发布请求,我正在使用 ASIFormDataRequest。以下是我的代码,请帮助我解决我的错误,在此先感谢。
- (IBAction)buttonTouched:(id)sender
{
NSLog(@"%d %@",[sender tag],[[NSUserDefaults standardUserDefaults] valueForKey:@"access_token"]);
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30, 90, 200, 20.0)];
[alertView addSubview:progressView];
[alertView show];
[progressView setProgress:0];
NSString *name=[videosToShow objectAtIndex:[sender tag]];
NSString *newFilePath = [NSString stringWithFormat:@"%@.mov", [self.path stringByAppendingPathComponent:name]];
NSLog(@"Content URL :%@;", newFilePath);
NSURL *url = [NSURL URLWithString:@"https://uploads.gdata.youtube.com/feeds/api/users/default/uploads"];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setRequestMethod:@"POST"];
NSLog(@"Auth Token== %@",[[NSUserDefaults standardUserDefaults] valueForKey:@"access_token"]);
[request setPostValue:[[NSUserDefaults standardUserDefaults] valueForKey:@"access_token"] forKey:@"authentication_token"];
[request setPostValue:devKey forKey:@"developer_key"];
[request setPostValue:@"abcabc" forKey:@"boundary_string"];
[request setPostValue:devKey forKey:@"content_length"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"xmlcontent" ofType:@"txt"];
NSString *strXml = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[request setPostValue:strXml forKey:@"API_XML_Request"];
[request setPostValue:@"video/mov" forKey:@"video_content_type"];
[request setPostValue:@"video/mov" forKey:@"Binary File Data"];
[request setFile:newFilePath withFileName:@"1.mov" andContentType:@"video/mov" forKey:@"uploaded"];
[request setUploadProgressDelegate:self];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request setShowAccurateProgress:YES];
[request startAsynchronous];
}
- (void)requestFinished:(ASIFormDataRequest *)request {
[alertView dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congrats!!!" message:@"File has been downloaded."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)requestFailed:(ASIFormDataRequest *)request1 {
NSError *error = [request1 error];
NSLog(@"%@", error);
}
下面是文件 xmlcontent.txt
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Bad Wedding Toast</media:title>
<media:description type="plain">
I gave a bad toast at my friend's wedding.
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>toast, wedding</media:keywords>
</media:group>
</entry>
下面是我得到的错误
错误域 = ASIHTTPRequestErrorDomain 代码 = 3 “需要身份验证” UserInfo = 0x1c8ed0 {NSLocalizedDescription = 需要身份验证}