Я пытаюсь загрузить видео на Youtube. Успешно загруженные видео на канал аккаунта. После этого я создал новый канал с именем "Deneme1". И я попытался загрузить этот канал с помощью api; но загружен на главную.
Мой код:
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;
}
}
Начиная с самого начала (что будет полезно для некоторых людей), я расскажу вам, что я сделал:
thiago.adriano26
имеет в своем ответе.C:\Users\User\AppData\Roaming\Google.Apis.Auth\Google.Apis.Auth.OAuth2.Responses.TokenResponse-<UserId>
. Это, похоже, связывает используемый UserId
с фактическим каналом. Пока это есть, эта связь между ними будет существовать. Удалив его или используя другой UserId (каждый канал имеет свой собственный UserId
и ChannelId
см. Здесь: https://support.google.com/youtube/answer/3250431?hl=ru) позволит вам выбрать новый канал из браузера,