gpt4 book ai didi

c# - 使用可恢复的C#代码上传YouTube的问题

转载 作者:行者123 更新时间:2023-12-03 06:22:25 24 4
gpt4 key购买 nike

当我尝试使用C#中的代码使用可恢复的上传将视频上传到您的视频时。
我收到错误消息“远程服务器返回错误:(410)消失。”。

这是我们用于使用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);

我认为由于上传网址版本2更改为版本3,我们正面临这一问题。
我怀疑我们不应该再使用“ http://uploads.gdata.youtube.com/resumable/feeds/api/users/” +帐户+“/上载”

您能帮我提供有关如何执行版本3的更改代码或新URL的信息吗?
这样,使用第3版的可恢复上传就可以成功上传视频。

最佳答案

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

使用Google .net客户端库

PM> Install-Package Google.Apis.YouTube.v3

在YouTube API v3中使用Oauth2。

/// <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 sample project抓取的代码

关于c# - 使用可恢复的C#代码上传YouTube的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32394740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com