我想将视频从我的应用上传到youtube。我正在使用示例YoutubeTest来实现此目的。我为我的应用设置了开发人员密钥和客户端ID。现在,当尝试使用示例源代码上传视频时,它会显示错误:
2012-03-19 10:51:07.947 YouTubeTest [539:f803] serviceBase:objectFetcher:failedWithStatus:400 data: 2012-03-19 10:51:07.985 YouTubeTest [539:f803]错误:错误Domain = com.google.GDataServiceDomain Code = 400“无法完成操作。(com.google.GDataServiceDomain错误400.)”UserInfo = 0x6c49e50 {}
有没有人成功实施过GData,可以从iphone应用上传视频到youtube。任何人都可以给我示例源代码。
答案 0 :(得分:2)
我在使用YouTubeTest应用时遇到了同样的问题。这是请求的代码:
(IBAction)uploadPressed:(id)sender {
NSString *devKey = [mDeveloperKeyField text];
GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:devKey];
NSString *username = [mUsernameField text];
NSString *clientID = [mClientIDField text];
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username
clientID:clientID];
// load the file data
NSString *path = [[NSBundle mainBundle] pathForResource:@"YouTubeTest" ofType:@"m4v"];
NSData *data = [NSData dataWithContentsOfFile:path];
NSString *filename = [path lastPathComponent];
// gather all the metadata needed for the mediaGroup
NSString *titleStr = [mTitleField text];
GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];
NSString *categoryStr = [mCategoryField text];
GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[category setScheme:kGDataSchemeYouTubeCategory];
NSString *descStr = [mDescriptionField text];
GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];
NSString *keywordsStr = [mKeywordsField text];
GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];
BOOL isPrivate = mIsPrivate;
GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category];
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:isPrivate];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:path
defaultMIMEType:@"video/mp4"];
// create the upload entry with the mediaGroup and the file data
GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
data:data
MIMEType:mimeType
slug:filename];
SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
}
答案 1 :(得分:1)
解决了我的问题。您的案例中的错误信息是不够的。但是如果从服务器打印出HTTPURLResponse,它将有助于发现错误。在我看来,关键字长度太长了。
答案 2 :(得分:1)
我遇到了同样的错误。但我确实通过反复试验找到了解决办法:)
实际上正如Youtube本身所述
您不再需要提供Client_Id。请删除它。
但实际问题在于登录凭据。当我登录为“xyz@gmail.com”时,API返回错误响应。当我提供没有域“xyz”的用户名时,它开始工作。
希望这有帮助!