将视频上传到 youtube 时,我如何知道哪个类别 ID 是什么类别名称
本文关键字:ID 别名 是什么 何知道 视频 youtube | 更新日期: 2023-09-27 17:56:39
我正在上传一个视频给yourube:在 form1 构造函数中:
UserCredential credential;
using (FileStream stream = new FileStream(@"D:'C-Sharp'Youtube-Manager'Youtube-Manager'Youtube-Manager'bin'Debug'client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None,
new FileDataStore("YouTube.Auth.Store")).Result;
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Default Video Title";
video.Snippet.Description = "Default Video Description";
video.Snippet.Tags = new string[] { "tag1", "tag2" };
video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public";
var filePath = @"C:'Users'bout0_000'Videos'test.mp4";
using (var fileStream = new FileStream(filePath, 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;
videosInsertRequest.ChunkSize = minimumChunkSize * 4;
videosInsertRequest.Upload();
}
在此示例中,我使用类别编号 22
video.Snippet.CategoryId = "22";
只有在上传视频后,我才在我的视频中看到YouTube网站,此类别是:人物和博客
如果我正在浏览此链接 https://developers.google.com/youtube/v3/docs/videoCategories/list 我可以在那里播放底部的 OAuth 2.0 授权请求。
但我仍然不明白在哪里可以看到按名称和 id 列出的所有类别的完整列表?例如:姓名:人物和博客 ID:22
找不到任何显示它的网站。
对以下位置进行 API 调用:
https://www.googleapis.com/youtube/v3/videoCategories?part=snippet®ionCode={two-character-region}&key={YOUR_API_KEY}
API 将返回所选区域的所有类别(名称和 ID)。请注意,同一类别在所有区域中应具有相同的 ID;但是,某些类别在某些地区不可用(这就是为什么您必须执行 API 调用...区域太多,无法以友好的方式列出所有可能的排列)。
下面是
我的程序的VB .NET源代码。此代码加载一个具有自定义类 (CategoryClass) 的组合框,该类包含所有有效的 CategoryId 和标题。我还包括了我的自定义类:类别类。可以使用其中一个免费转换器将其转换为 C# .NET。
Private Sub GetVideoCategories()
Dim objYouTubeService As YouTubeService
AddToLog("GetVideoCategories Begin", True, False)
Try
objYouTubeService = New YouTubeService(New BaseClientService.Initializer() With { _
.HttpClientInitializer = OAUth2Credential, _
.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name})
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "GetVideoCategories - Initialize YouTubeService")
End
End Try
Dim objCategories As VideoCategoryListResponse = Nothing
Try
Dim objRequest As VideoCategoriesResource.ListRequest = New VideoCategoriesResource.ListRequest(objYouTubeService, "id,snippet")
objRequest.Hl = "en_US"
objRequest.RegionCode = "US"
objCategories = objRequest.Execute
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "GetVideoCategories - VideoCategories List Request")
End
End Try
cmbCategory.DisplayMember = "Title"
cmbCategory.ValueMember = "Id"
For Each obj As VideoCategory In objCategories.Items
cmbCategory.Items.Add(New CategoryClass(obj.Id, obj.Snippet.Title))
If obj.Snippet.Title.Contains("News") Then
intDefaultCategoryIndex = cmbCategory.Items.Count - 1
End If
Next
cmbCategory.SelectedIndex = intDefaultCategoryIndex
AddToLog("GetVideoCategories End", True, False)
End Sub
Friend Class CategoryClass
Dim m_Id As String
Dim m_Title As String
Sub New(ByVal Id As String, ByVal Title As String)
m_Id = Id
m_Title = Title
End Sub
Property ID As String
Get
ID = m_Id
End Get
Set(value As String)
m_Id = value
End Set
End Property
Property Title As String
Get
Title = m_Title
End Get
Set(value As String)
m_Title = value
End Set
End Property
Overrides Function ToString() As String
ToString = m_Id & "|" & m_Title
End Function
End Class