Try reading this document about YouTube Subscribe Button
The YouTube Subscribe Button lets you add a one-click Subscribe
button to any page. The button lets people subscribe to your YouTube channel without having to leave your site to either log in to YouTube or confirm their subscriptions.
To add a button, your application needs to load this JavaScript file:
https://apis.google.com/js/platform.js
You can add a button by using an element, such as a <div>
, that sets its class
to g-ytsubscribe
and uses other attributes to customize the button. The code below shows a simple integration that displays a Subscribe
button for the GoogleDevelopers channel.
<script src="https://apis.google.com/js/platform.js"></script>
<div class="g-ytsubscribe" data-channel="GoogleDevelopers"></div>
class
- Set the value to g-ytsubscribe
. This class identifies the <div>
element as a container for a subscription button and enables YouTube to dynamically resize the embedded button as explained in the next section.
You must specify a value for one of the following two attributes:
data-channel
– The name of the channel associated with the button. Sample value: GoogleDevelopers
.
data-channelid
– The channel ID associated with the button. Sample value: UC_x5XG1OV2P6uZZ5FSM9Ttw
. You can retrieve your channel ID in your YouTube account settings or by using the APIs Explorer at the end of this document. Learn more about working with channel IDs.
Using data-channelid
:
<script src="https://apis.google.com/js/platform.js"></script>
<div class="g-ytsubscribe" data-channelid="UC_x5XG1OV2P6uZZ5FSM9Ttw"></div>
To retrieve your own channel ID, authorize the request by setting the Authorize requests using OAuth 2.0 button at the top of the form to ON. Then send the request by clicking the blue button at the bottom of the form.
To retrieve the channel ID for any channel that has a YouTube channel name, set the forUsername property in the form below to the channel name and the mine property to false.
Sources you can use to understand how to get the Channel ID:
Hope this helps!