将视频上传到 youtube 时,我如何知道什么类别 ID 是什么类别名称?
How do i know what category id is what category name when uploading a video to youtube?
我正在向 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 网站上看到这个类别是:人物和博客
如果我正在浏览此 link 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 将 return 您选择的区域的所有类别(名称和 ID)。请注意,同一类别在所有地区应具有相同的 ID;但是,某些类别在某些地区不可用(这就是为什么您必须进行 API 调用...地区太多,无法以友好的方式列出所有可能的排列)。
下面是我程序中的 VB .NET 源代码。此代码加载带有自定义 Class (CategoryClass) 的 ComboBox,其中包括所有有效的 CategoryId 和标题。我还包含了我的 Custom Class: CategoryClass。您可以使用其中一种免费转换器将其转换为 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
我正在向 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 网站上看到这个类别是:人物和博客
如果我正在浏览此 link 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 将 return 您选择的区域的所有类别(名称和 ID)。请注意,同一类别在所有地区应具有相同的 ID;但是,某些类别在某些地区不可用(这就是为什么您必须进行 API 调用...地区太多,无法以友好的方式列出所有可能的排列)。
下面是我程序中的 VB .NET 源代码。此代码加载带有自定义 Class (CategoryClass) 的 ComboBox,其中包括所有有效的 CategoryId 和标题。我还包含了我的 Custom Class: CategoryClass。您可以使用其中一种免费转换器将其转换为 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