Logo
Section 1 / 2

修改 YouTube 频道

了解如何使用 YouTube Data API 向频道添加横幅并更新它。

导入

修改 YouTube 频道

了解如何使用 YouTube Data API 向频道添加横幅并更新它。

`Channels` 资源包含订阅者数量、观看次数、视频数量、频道名称和描述等信息,帮助用户通过内容在互联网上建立自己的存在感。

...

代码示例

1https://www.googleapis.com/upload/youtube/v3/channelBanners/insert
1import fetch from 'node-fetch'; 2import fs from 'fs'; 3 4const endpointUrl = new URL('https://www.googleapis.com/upload/youtube/v3/channelBanners/insert'); 5 6// 定义请求头参数 7const headerParameters = { 8 Authorization: 'Bearer {{ACCESS_TOKEN}}', 9 Accept: 'application/octet-stream', 10}; 11 12const imgPath = fs.readFileSync('YoutubeBanner.jpg'); 13 14const options = { 15 method: 'POST', 16 headers: headerParameters, 17 body: imgPath, 18}; 19 20// 发送 API 请求的函数 21async function uploadChannelBanner() { 22 try { 23 const response = await fetch(endpointUrl, options); 24 printResponse(response); 25 } catch (error) { 26 printError(error); 27 } 28} 29 30uploadChannelBanner();

No configuration found for ID: 8af59a83b2b7d2882c5b416ce75f8952190793dd12717dbc57c97e9a354f875e

字段类型描述
kind字符串表示 API 调用的资源类型。
etagETag包含资源的 ETag 标识。
url字符串包含上传图片的 URL。

代码示例

1https://www.googleapis.com/youtube/v3/channels

字段类型类别描述
part字符串必填此参数有两个作用:指定用户将设置的属性,以及指定 API 响应中包含的属性,包括 brandingSettings、invideoPromotion、localizations。
onBehalfOfContentOwner字符串可选用于标识认证用户正在代表内容所有者进行更改。
id字符串必填用于通过频道 ID 指定要更新的频道。
brandingSettings.channel.country字符串可选用于更新频道所属国家。
brandingSettings.channel.description字符串可选用于更新频道描述。
1import fetch from 'node-fetch'; 2 3const endpointUrl = new URL('https://youtube.googleapis.com/youtube/v3/channels'); 4 5// 定义请求头参数 6const headerParameters = { 7 Authorization: 'Bearer {{ACCESS_TOKEN}}', 8 Accept: 'application/json', 9}; 10 11const queryParameters = new URLSearchParams({ 12 part: 'brandingSettings', 13}); 14 15// 定义请求体参数 16const bodyParameters = JSON.stringify({ 17 id: '{{CHANNEL_ID}}', 18 brandingSettings: { 19 channel: { 20 description: '这是频道的示例描述', 21 }, 22 }, 23}); 24 25const options = { 26 method: 'PUT', 27 headers: headerParameters, 28 body: bodyParameters, 29}; 30 31async function updateChannel() { 32 try { 33 endpointUrl.search = queryParameters; 34 const response = await fetch(endpointUrl, options); 35 printResponse(response); 36 } catch (error) { 37 printError(error); 38 } 39} 40 41updateChannel();

字段类型描述
kind字符串表示 API 调用的资源类型。
etagETag包含资源的 ETag 标识。
id字符串包含正在更新的频道 ID。
brandingSettings.channel.description字符串包含频道的描述信息。
brandingSettings.channel.title字符串包含频道的标题。

简介

查看我们的 YouTube 频道