Im пытается создать веб-сайт, с которого вы можете загружать видео с вашего устройства на YouTube, но сможете просматривать те конкретные видеоролики, которые вы загрузили на моем сайте. (Здесь есть еще одна цель)Youtube api upload video.net
Я использую .net C#, и у меня есть ключи oauth и ключи api для разработчиков, загружены json-файл и т. Д. Я загрузил образец кода, который у Google есть для этого, но, похоже, он не работает, не совсем уверен, как он работает.
Может кто-нибудь, пожалуйста, помогите мне с этим/объясните это мне?
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
/// <summary>
/// Summary description for Video_Upload
/// </summary>
public class Video_Upload
{
public Video_Upload()
{
//
// TODO: Add constructor logic here
new Video_Upload().Run().Wait();
}
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("Client_id_googleApi.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
//VIDEO INFO AND DETAILS
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Test Video 1";
video.Snippet.Description = "Testing Video Upload";
video.Snippet.Tags = new string[] { "Test", "First" };
video.Snippet.CategoryId = "17";//category id for sport // See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Snippet.ChannelId = "UCfvR-wqeoHmAGrHnoQRfs9w";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public"; // or "private" or "public"
var filePath = @"C:\Users\siobhan\Documents\Visual Studio 2015\WebSites\FYP_November\GP010149.avi"; // Replace with path to actual movie file.
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
await videosInsertRequest.UploadAsync();
}
void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
{
switch (progress.Status)
{
case UploadStatus.Uploading:
Console.WriteLine(progress.BytesSent, " bytes sent.");
break;
case UploadStatus.Failed:
Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
break;
}
}
void videosInsertRequest_ResponseReceived(Video video)
{
Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
}
}
}
Не без * каких-либо * информации о том, какой код вы используете или что не работает, нет. Что бы вы ни показывали на экране, мы не можем видеть это. – David
, не использованные для использования этого сайта, выгрузили код выше – shove195
Каков ваш конкретный вопрос относительно этого кода? Каким образом он терпит неудачу? Когда вы отлаживаете это, где/как конкретно это происходит? – David