我正在使用下面的代码将视频上传到YouTube。它适用于我的一个YouTube帐户,但不适用于另一个帐户。我只需替换客户端 ID 和客户端密钥即可在 YouTube 帐户之间切换。关于为什么它不适用于我的其他 YouTube 帐户的任何想法?
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier = ClientId,
ClientSecret = ClientSecret
};
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
var youtube = new YouTubeService(new BaseClientService.Initializer()
{
Authenticator = auth
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Demo 1";
video.Snippet.Description = "Demo 1a";
video.Snippet.Tags = new string[] { "tag1", "tag2" };
video.Snippet.CategoryId = "22";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "private";
var filePath = @"C:wildlife.wmv";
var fileStream = new FileStream(filePath, FileMode.Open);
var videosInsertRequest = youtube.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
var uploadThread = new Thread(() => videosInsertRequest.Upload());
uploadThread.Start();
uploadThread.Join();
您无需更改客户端 ID 和密钥即可上传到不同的帐户。客户端 ID 和密钥定义开发人员,对于将要上传的通道,您只需使用该登录进行授权。