使用可恢复c#代码上传youtube的问题



当我尝试使用c#中的代码使用可恢复上传视频到youtube时。我得到一个错误消息"远程服务器返回了一个错误:(410)Gone."。

这是我们使用c#上传视频的代码。

var credentials = new GDataCredentials(_account, _password);
_authenticator = new ClientLoginAuthenticator("YouTubeUploader", ServiceNames.YouTube, credentials){DeveloperKey = _developerKey};
_resumableUploader = new ResumableUploader();
_resumableUploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(UlAsyncOperationCompleted);
_resumableUploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(UlAsyncOperationProgress);
var v = new Video
                        {
                            Title = "some title",
                            Description = "some description",
                            Keywords = "list of keywords separated by comma",
                            Private = false
                        };
            v.Tags.Add(new MediaCategory("Entertainment"));
            string contentType = MediaFileSource.GetContentTypeForFileName("Video file name");
            v.MediaSource = new MediaFileSource("video file name", contentType);
            // add the upload uri to it
            var link =
                new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + Account + "/uploads")
                    {Rel = ResumableUploader.CreateMediaRelation};
            v.YouTubeEntry.Links.Add(link);
              XmlExtension unlistedAccessControlXmlExtension = CreateAccessControlXmlExtension("list", "denied");
            XmlExtension noCommentAccessControlXmlExtension = CreateAccessControlXmlExtension("comment", "denied");
            XmlExtension rat1 = CreateAccessControlXmlExtension("commentVote", "denied");
            XmlExtension rat2 = CreateAccessControlXmlExtension("videoRespond", "denied");
            XmlExtension rat3 = CreateAccessControlXmlExtension("rate", "denied");
            v.YouTubeEntry.ExtensionElements.Add(rat1);
            v.YouTubeEntry.ExtensionElements.Add(rat2);
            v.YouTubeEntry.ExtensionElements.Add(rat3);
            v.YouTubeEntry.ExtensionElements.Add(unlistedAccessControlXmlExtension);
            v.YouTubeEntry.ExtensionElements.Add(noCommentAccessControlXmlExtension);
            var info = new YouTubeFileInfo(desc.Id) { Status = YouTubeFileInfo.YouTubeFileStatus.Uploading, FileName = fileName };
            _resumableUploader.InsertAsync(_authenticator, v.YouTubeEntry, data);

我认为我们正面临这个问题,因为上传URL版本2到版本3的变化。我怀疑我们不应该再使用"http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + Account + "/uploads"

你能帮我提供一个关于如何做更改代码或版本3的新URL的信息。这样视频上传就可以成功使用版本3的可恢复上传

您遇到的问题是您正在尝试使用不再工作的登录名和密码登录。您要么需要将其更改为OAuth2,我也建议您升级到当前版本的YouTube API。

使用Google .net客户端库

PM> Install-Package google . api . youtube。v3

使用Oauth2与YouTube API v3.

/// <summary>
        /// Authenticate to Google Using Oauth2
        /// Documentation https://developers.google.com/accounts/docs/OAuth2
        /// </summary>
        /// <param name="clientId">From Google Developer console https://console.developers.google.com</param>
        /// <param name="clientSecret">From Google Developer console https://console.developers.google.com</param>
        /// <param name="userName">A string used to identify a user.</param>
        /// <returns></returns>
        public static YouTubeService AuthenticateOauth(string clientId, string clientSecret, string userName)
        {
            string[] scopes = new string[] { YouTubeService.Scope.Youtube,  // view and manage your YouTube account
                                             YouTubeService.Scope.YoutubeForceSsl,
                                             YouTubeService.Scope.Youtubepartner,
                                             YouTubeService.Scope.YoutubepartnerChannelAudit,
                                             YouTubeService.Scope.YoutubeReadonly,
                                             YouTubeService.Scope.YoutubeUpload};
            try
            {
                // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
                                                                                             , scopes
                                                                                             , userName
                                                                                             , CancellationToken.None
                                                                                             , new FileDataStore("Daimto.YouTube.Auth.Store")).Result;
                YouTubeService service = new YouTubeService(new YouTubeService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "YouTube Data API Sample",
                });
                return service;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                return null;
            }
        }

摘自YouTube示例项目的代码

相关内容

  • 没有找到相关文章

最新更新