使用c#在youtube api中添加缩略图?

时间:2017-05-03 05:55:17

标签: c# video youtube youtube-api youtube-data-api

我在visual studio中制作了一个程序,使用ffmpeg呈现具有静态图像的视频,然后将其上传到youtube,但它也可以上传未呈现的视频。

对于那些我想指定使用的缩略图的人,是否可以使用c#设置视频的缩略图?

我查看了有关此内容的文档,但它不包含任何c#/ .net示例(https://developers.google.com/youtube/v3/docs/thumbnails/set

2 个答案:

答案 0 :(得分:1)

您可以使用Youtube SDK和类似这样的流来设置缩略图:

Unable to validate event. errors:{'Reservations': [{0: [{'Instances': [{0: [{'Tags': [{0: [{'Key': ['unallowed value Namespace']}], 1: [{'Key': ['unallowed value some:internal:tag']}], 2: [{'Key': ['unallowed value SomeInternalThing']}], 5: [{'Key': ['unallowed value Name']}]}]}]}]}]}]}

在该示例中,您收到一个URL并为该视频设置了缩略图,但是您可以将流更改为本地流或任何其他流。

答案 1 :(得分:0)

假设您使用的是Google API .net客户端库,此代码应该可以使用

public class ThumbnailsSetOptionalParms
        {
            /// Note: This parameter is intended exclusively for YouTube content partners. The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value. This parameter is intended for YouTube content partners that own and manage many different YouTube channels. It allows content owners to authenticate once and get access to all their video and channel data, without having to provide authentication credentials for each individual channel. The actual CMS account that the user authenticates with must be linked to the specified YouTube content owner.
            public string OnBehalfOfContentOwner { get; set; }  

        }

        /// <summary>
        /// Uploads a custom video thumbnail to YouTube and sets it for a video. 
        /// Documentation https://developers.google.com/youtube/v3/reference/thumbnails/set
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated YouTube service.</param>  
        /// <param name="videoId">The videoId parameter specifies a YouTube video ID for which the custom video thumbnail is being provided.</param>
        /// <param name="optional">Optional paramaters.</param>        
        /// <returns>ThumbnailSetResponseResponse</returns>
        public static ThumbnailSetResponse Set(YouTubeService service, string videoId, ThumbnailsSetOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                    throw new ArgumentNullException("service");
                if (videoId == null)
                    throw new ArgumentNullException(videoId);

                // Building the initial request.
                var request = service.Thumbnails.Set(videoId);

                // Applying optional parameters to the request.                
                request = (ThumbnailsResource.SetRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return request.Execute();
            }
            catch (Exception ex)
            {
                throw new Exception("Request Thumbnails.Set failed.", ex);
            }
        }


    }

从{。{3}} youtube-Data-API

的Google .net客户端示例项目中删除了代码

我没有任何用于上传文件本身的代码,但有一个关于Drive API的非常好的教程应该是类似的,你应该能够改变ThumbnailsSample.Cs这是我唯一的文档了解媒体上传。