gpt4 book ai didi

c# - 将视频上传到特定 channel /Youtube

转载 作者:太空宇宙 更新时间:2023-11-03 23:48:03 25 4
gpt4 key购买 nike

我正在尝试将视频上传到 Youtube。已成功将视频上传到帐户的 channel 。之后我创建了名为“Deneme1”的新 channel 。我试着用 api 上传到那个 channel ;但上传到主。

我的代码:

    public static string UploadVideo(string FilePath, string Title, string Description)
{
YouTubeRequestSettings settings;
YouTubeRequest request;
string devkey = "api key";
string username = "mail@gmail.com";
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 的特定 channel 。

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/

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