gpt4 book ai didi

iphone - 在YouTube上上传视频

转载 作者:行者123 更新时间:2023-12-03 05:42:53 26 4
gpt4 key购买 nike

我需要将视频从我的iPhone应用程序上传到youtube,我已经获得了访问 token ,形式为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>

以下是我得到的错误

Error Domain=ASIHTTPRequestErrorDomain Code=3 "Authentication needed" UserInfo=0x1c8ed0 {NSLocalizedDescription=Authentication needed}

最佳答案

您正在使用GData库,但尚未链接/添加它。查看XCode 4中的GData Objective-C客户端安装程序,了解如何正确构建/链接GData库。

关于iphone - 在YouTube上上传视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13269027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com