我正在尝试将视频上传到Youtube。已成功将视频上传到帐户的频道。
之后,我创建了名为“ Deneme1”的新频道。我尝试使用api上传到该频道;但已上传到main。
我的代码:
public static string UploadVideo(string FilePath, string Title, string Description)
{
YouTubeRequestSettings settings;
YouTubeRequest request;
string devkey = "api key";
string username = "[email protected]";
string password = "password";
settings = new YouTubeRequestSettings("Deneme1", devkey, username, password) { Timeout = 10000000 };
request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = Title;
newVideo.Description = Description;
newVideo.Private = true;
newVideo.YouTubeEntry.Private = false;
newVideo.Keywords = "asd";
newVideo.Tags.Add(new MediaCategory("Sports", YouTubeNameTable.CategorySchema));
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/flv");
Video createdVideo = request.Upload(newVideo);
return createdVideo.VideoId;
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
string videopath, videotitle, videodesc;
videopath = @"C:\Users\Ercin\Dropbox\Cloudy\Visual Studio\Projects\videoupload\videoupload\badstart.flv";
videotitle = "test title";
videodesc = "test description";
UploadVideo(videopath, videotitle, videodesc);
}
catch (Exception exception)
{
Response.Write("Upload failed: " + exception.Message);
}
任何帮助都将非常棒!
最佳答案
此代码对我来说很好,可以上传到我在用户名中输入ChannelId的特定频道。
public static Google.Apis.YouTube.v3.YouTubeService AuthenticateOaut(string clientId, string clientSecret, string userName)
{
string[] scopes = new string[] { Google.Apis.YouTube.v3.YouTubeService.Scope.Youtube, // view and manage your YouTube account
Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubeForceSsl,
Google.Apis.YouTube.v3.YouTubeService.Scope.Youtubepartner,
Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubepartnerChannelAudit,
Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubeReadonly,
Google.Apis.YouTube.v3.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;
Google.Apis.YouTube.v3.YouTubeService service = new Google.Apis.YouTube.v3.YouTubeService(new Google.Apis.YouTube.v3.YouTubeService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Web client 1",
});
return service;
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
return null;
}
}
关于c# - 将视频上传到特定 channel /Youtube,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26907028/