2
這是當視頻文件上傳的事件:我用了一個破發點如何在視頻文件上傳後獲得YouTube視頻鏈接?
public static TimeSpan time = new TimeSpan();
Video objects = null;
private void videosInsertRequest_ResponseReceived(Video obj)
{
System.Timers.Timer aTimer;
aTimer = new System.Timers.Timer();
aTimer.Elapsed += aTimer_Elapsed;
aTimer.Interval = 10000;
aTimer.Enabled = false;
uploadstatus = obj.Status.UploadStatus;
if (uploadstatus == "uploaded")
{
fileuploadpercentages = 100;
stopwatch.Stop();
var milliseconds = stopwatch.ElapsedMilliseconds;
time = stopwatch.Elapsed;
time = TimeSpan.FromSeconds(Math.Round(time.TotalSeconds));
uploadstatus = "file uploaded successfully";
string[] lines = File.ReadAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt");
File.WriteAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt", lines.Skip(1));
if (Form1.uploadedFilesList.Count > 0)
Form1.uploadedFilesList.RemoveAt(0);
}
if (uploadstatus == "Completed")
{
}
objects = obj;
}
,我看到該變量OBJ有一些性質其中之一就是ID。但沒有鏈接屬性或顯示鏈接的內容。
這就是我上傳視頻的方式,但我不確定它是否會幫助我需要在上傳完成後找到上傳的視頻鏈接。
private void UploadVideo(string FileName, string VideoTitle, string VideoDescription)
{
try
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
video.Snippet = new VideoSnippet();
video.Snippet.Title = VideoTitle;
video.Snippet.Description = VideoDescription;
video.Snippet.Tags = new string[] { "tag1", "tag2" };
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public";
using (var fileStream = new FileStream(FileName, FileMode.Open))
{
const int KB = 0x400;
var minimumChunkSize = 256 * KB;
var videosInsertRequest = youtubeService.Videos.Insert(video,
"snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
// The default chunk size is 10MB, here will use 1MB.
videosInsertRequest.ChunkSize = minimumChunkSize * 3;
dt = DateTime.Now;
totalBytes = fileStream.Length;
videosInsertRequest.Upload();
}
}
catch (Exception errors)
{
string errorss = errors.ToString();
}
}