概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 YouTube Subscribe Button,您可以向任何网页添加 Subscribe
按钮。此按钮会链接到 YouTube 频道。点击该按钮后,系统会在新窗口中打开 YouTube 频道页面,以便用户确认订阅。
要添加此按钮,您的应用程序需要加载以下 JavaScript文件:
https://apis.google.com/js/platform.js
然后,您可以使用某个元素(例如 <div>
)添加按钮,该元素将其 class
设置为 g-ytsubscribe
,并使用其他属性自定义按钮。以下代码展示了一个简单的集成,用于显示 GoogleDevelopers 频道的 Subscribe
按钮。
<script src="https://apis.google.com/js/platform.js"></script>
<div class="g-ytsubscribe" data-channel="GoogleDevelopers"></div>
您也可以使用 Google+ JavaScript API 来动态呈现按钮。
配置选项
以下按钮显示了订阅按钮的不同布局和配置选项。标准频道的按钮会显示订阅人数,也可能不显示。
默认的按钮语言为用户使用的语言,或根据未登录用户的所在位置进行设置。
标准频道
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Overview\n\nThe YouTube Subscribe Button lets you add a `Subscribe` button to any page. The button links to a YouTube channel. Upon clicking the button, the YouTube channel page opens in a new window so that the user can confirm the subscription.\n\nTo add a button, your application needs to load this JavaScript file: \n\n```\nhttps://apis.google.com/js/platform.js\n```\n\nYou can then add a button by using an element, such as a `\u003cdiv\u003e`, that sets its `class` to `g-ytsubscribe` and uses other attributes to customize the button. The following code shows a simple integration that displays a `Subscribe` button for the GoogleDevelopers channel. \n\n```\n\u003cscript src=\"https://apis.google.com/js/platform.js\"\u003e\u003c/script\u003e\n\u003cdiv class=\"g-ytsubscribe\" data-channel=\"GoogleDevelopers\"\u003e\u003c/div\u003e\n```\n\nYou can also use the [Google+ JavaScript API](/+/web/api/javascript) to render a button dynamically.\n\nConfiguration options\n---------------------\n\nThe buttons below show different layout and configuration options for subscription buttons. Buttons for standard channels are shown with and without subscriber counts.\n\nThe button language defaults to the user's language settings or is set based on the user's location for logged-out users.\n\n### Standard channels\n\n| Buttons ||\n|-------------------------------|---|\n| Default button | |\n| Default button | |\n| Full layout (includes avatar) | |\n| Full layout (includes avatar) | |\n| Full layout, dark theme | |\n| Full layout, dark theme | |"]]