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 来动态呈现按钮。
注意:如果与该按钮相关联的频道是付费的订阅频道,则按钮会自动链接到相关频道而非订阅用户。
配置选项
以下按钮展示了订阅按钮的不同布局和配置选项。标准频道的按钮可以选择显示或不显示订阅人数。您可以参阅以下内容为自己的频道配置一个按钮。
默认的按钮语言为用户使用的语言,或根据未登录用户的所在位置进行设置。
标准频道
付费频道
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2019-06-11 UTC.