我想将视频上传到YouTube channel 。我尝试使用以下代码。以下代码可以上传视频,但问题是我无法附加其信息(视频标题,描述和标签)。上传后仅显示视频标题作为“未知”且没有标签或描述。我见过CodingTofu,Dev7Dev Blog- iOS Sample Code和许多其他问答,但我不明白自己在哪里犯错。
NSString* title = video.title;
NSString* description = video.videoDescription;
NSData* data = video.data;
NSMutableArray* tags = video.tags.mutableCopy;
GTLYouTubeVideo *yVideo = [GTLYouTubeVideo object];
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet alloc];
snippet.title = title;
snippet.descriptionProperty = description;
[tags addObject:DEFAULT_KEYWORD];
NSString* tag = [UploadController generateKeywordFromPlaylistId:UPLOAD_PLAYLIST];
[tags addObject:tag];
snippet.tags = tags;
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus alloc];
status.privacyStatus = @"public";
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:@"video/*"];
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosInsertWithObject:yVideo part:@"snippet,status" uploadParameters:uploadParameters];
service.uploadProgressBlock = ^(GTLServiceTicket* ticket, unsigned long long totalBytesUploaded, unsigned long long totalBytesExpectedToUpload){
CGFloat percentage = totalBytesUploaded/totalBytesExpectedToUpload;
NSLog(@"\nUploaded percentage %%(%0.2f)",percentage);
};
[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLYouTubeVideo *insertedVideo, NSError *error) {
//[waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
if (error == nil)
{
NSLog(@"File ID: %@", insertedVideo.identifier);
return;
}
else
{
NSLog(@"An error occurred: %@", error);
return;
}
}];
告诉我是否需要其他详细信息
谢谢。
对不起,我的英语不好。
最佳答案
我误会了
在上面的代码中,我必须添加
GTLYouTubeVideo *yVideo = [GTLYouTubeVideo object];
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus alloc];
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet alloc];
*******
*******
*******
yVideo.snippet = snippet;//This part i forgot to add in my code
yVideo.status = status;//This part i forgot to add in my code
[service executeQuery........
这可能会对遇到相同问题的人有所帮助。
关于ios - iOS上载带有视频信息GTLServiceYoutube的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36077449/