iOS上传带有视频信息的视频GTLServiceYoutube

时间:2016-03-18 06:17:41

标签: ios objective-c video youtube youtube-data-api


我想上传视频到youtube channel.i尝试使用以下Code.the波纹管代码工作上传视频,但问题是,我无法附加其信息(视频标题,描述和标签)。上传后它只显示视频标题为“未知”,没有标签或描述。我见过CodingTofuDev7Dev Blog- iOS Sample Code和许多其他Q& A但我无法理解我在哪里弄错了。

    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;
            }
        }];

告诉我你是否需要任何进一步的细节 谢谢。 抱歉我的英语不好。

1 个答案:

答案 0 :(得分:0)

我得到了错误, 在上面的代码中,我必须添加

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........

这可能会对面临同样问题的人有所帮助。