此页面介绍了如何使用 YouTube Data API (v3) 执行与检索和更新频道数据相关的功能。channel
资源包含播放列表 ID,用于标识频道已上传和顶过的视频。如需在调用 channels.list
方法时提取此信息,请确保 part
参数值包含 contentDetails
资源部分。
检索频道的相关信息
调用 channels.list
方法可检索特定渠道的相关信息。标识频道的方式有以下几种:
-
将
mine
参数值设为true
可检索当前已通过身份验证的用户的 YouTube 频道的相关信息。您的请求必须使用 OAuth 2.0 进行授权。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list? part=snippet,contentDetails,brandingSettings &mine=true
-
将
forUsername
参数设置为 YouTube 用户名,即可检索与该用户名关联的频道的信息。此示例将forUsername
参数值设为Google
,以检索 Google 官方 YouTube 频道的信息。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list? part=snippet,contentDetails &forUsername=Google
-
将
id
参数设置为可唯一标识您要检索其信息的频道的 YouTube 频道 ID。此示例中的id
参数设为UCK8sQmJBp8GCxrOtXWBpyEA
,也表示 Google 的官方 YouTube 频道。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list? part=snippet,contentDetails &id=UCK8sQmJBp8GCxrOtXWBpyEA
设置频道的品牌信息
此示例更新了频道的品牌选项。该示例包含两个步骤:
-
第 1 步:检索频道的品牌选项
调用
channels.list
方法,并将part
参数值设为brandingSettings
,并将mine
参数值设为true
。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list? part=brandingSettings &mine=true
您的应用可以显示检索到的设置,以便用户修改要更新的设置。
-
第 2 步:更新频道的品牌选项
调用
channels.list
方法并设置以下值:下面的 API Explorer 链接会创建一个
channel
,其中包含以下品牌设置:{ "id": "CHANNEL_ID", "brandingSettings": { "channel": { "description": "A great channel to be enjoyed by all.", "moderateComments": true, "showRelatedChannels": true, "showBrowseView": true, "featuredChannelsTitle": "Featured Channel Stuff", "featuredChannelsUrls": [ "UC_x5XG1OV2P6uZZ5FSM9Ttw", "UCBR8-60-B28hp2BmDPdntcQ", "UCK8sQmJBp8GCxrOtXWBpyEA" ], "profileColor": "#006600" } } }
如需在 API Explorer 中完成请求,您需要将
id
属性的值设置为经过身份验证的用户的渠道的渠道 ID。此外,您还应设置与当前设置相符的图片属性。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.update? part=brandingSettings
管理频道版块
该 API 支持使用 channelSections.list、channelSections.insert、channelSections.update 和 channelSections.delete 方法管理频道版块。频道版块是频道推介的一组视频。例如,版块可以包括频道最新上传的内容、最热门上传的视频,以及来自一个或多个播放列表的视频。
以下示例检索了 Google 官方 YouTube 频道的频道版块。请求调用 channelSections.list
方法,并将 channelId
参数值设为 UCK8sQmJBp8GCxrOtXWBpyEA
,即 Google 渠道的渠道 ID。
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channelSections.list? part=snippet,contentDetails &channelId=UCK8sQmJBp8GCxrOtXWBpyEA
如果您将 mine
参数值设为 true
,而不是使用 channelId
参数,那么此请求需要授权。该参数表示您检索的是当前已通过身份验证的用户的频道的频道版块。
上传频道并为其设置水印图片
您可以调用 watermarks.set
方法来上传水印图片,并为频道设置水印。该图片会在指定频道的视频播放过程中显示。您还可以指定图片将链接到的目标频道,以及能够确定水印显示时间及可见时间的具体时间细节。
watermarks.unset
方法可删除频道的水印图片。
遗憾的是,无法使用 API Explorer 测试此查询,因为 API Explorer 不支持上传媒体文件,而这是此方法的必要条件。