How to host your YouTube channel on your website using the YouTube API key and your YouTube channel key

Do you have a YouTube channel with several videos and certainly dream of hosting it directly on your website? If so, this article is for you. Through its YouTube API key, Google gives you the possibility to host your channel on your website.

Indeed, by using this feature, you can automatically connect your website to your YouTube channel and see your videos appear automatically on your website each time you add them. In other words, your video library codes take care of updating your website.

This article will see how to use the YouTube API V3 key and channel ID to sync content. The article is in three parts. In the first part, we will see how to create the identifiers. Then we will use the codes that you can copy and paste to do the synchronization. Finally, the last part of this article will give you tips to make it easy depending on the type of web solution you are using. If you are on WordPress, you can, for example, download our extension to save time.

Why host your YouTube channel on your website

There may be several reasons for this:

  •  Expand your reach: When your videos are on YouTube, a user needs to be there to see them. If you have them on your website, it can be a way to target people outside of YouTube.
  • Increase the visibility of your website. Video content seems to have more reach than articles. To this end, if you have your videos on your website, it can help increase your visibility.
  • Grow your brand. The more popular you are online, the more likely you will grow your brand.

Some Benefits of YouTube API Key

APIs (or Application Programming Interface) gives you the benefits of connecting to data from an external platform as efficiently as possible. With the YouTube API you can connect the feeds from your YouTube channel to your website. Below are some advantages compared to the manual procedure.

  • you don’t need to copy your videos manually Through API you are able to get the link and several other data
  • Double your online visibility. Videos on your site have the advantage of increasing your traffic. So by using the API you could create a video library and keep your visitors on your website
  • You have flexibility in data manipulation. With the API, you can, for example, get the description, summary, banner photo of your video. In addition, you can customize the design of your site to your liking.

Prerequisites for connecting YouTube to your website

To be able to connect your channel to your site, you obviously need:

  • from a YouTube channel,
  • of a website and
  • An account at Google Cloud.

I’m going in this part to explain how to proceed to have these three elements if you do not have any.

How to create your YouTube channel

Gmail users automatically get a YouTube channel. To create your YouTube channel, you must have a Gmail or G-Suite account.

For all Gmail and G-Suite subscribers

  • Visit the YouTube site and click “connect.”  When you click on the button, will the site redirect you to the login page?
  • Enter your username and password to log in.
  • You will be redirected to the YouTube page. You can click the camera icon in the top and right corner to add your videos.

If you don’t have a Gmail or G suite account

  • Go to YouTube, then click “connect.” Once that’s done, you will most likely find yourself on a page asking you to create your account.
  • Click on “Create an account.” (you will have the choice between creating an account for yourself or managing your business).
  • Choose the option that fits with your goals.
  • Then, follow the steps offered by Google to create your account. In most cases, you need your name, first name, a unique email (which you will choose) and the password.
  • To add videos, click the camera icon in the top-right corner of your YouTube page.

How to host your YouTube channel on your website using the YouTube API key, your channel ID and PHP [Updated article]

How to Create a Google Cloud Account to Retrieve YouTube API Key

The Google Cloud account is an interface suggesting a set of APIs, including the YouTube API. We will see how to have a Google Cloud account To create a Google Cloud account follow these steps:

  • go to the Google Cloud website and click on “Go to console”
  • Just like the creation of the YouTube account, you will be redirected to the login page
  • You must use an existing Gmail or G-Suite account or create one on this page.
  • Once connected, you must follow the steps advised by the platform to configure your account.
  • You must add payment information to be able to activate your account

Please note that Google Cloud offers paid applications based on the number of requests per day. You might never have to pay if you use a little application. I advise you to refer to the general conditions before committing yourself.

Google Cloud Console

How to create a website?

I guess if you want to connect YouTube to your site, it’s apparent that you have one. Otherwise, the easiest option to use this article is to have a self-hosted site. Indeed, to modify the codes of your site, you must have the necessary authorizations. Online website builders or free solutions do not offer this freedom.

Option 1: Create your website by yourself

The generic steps for creating a self-managed site are as follows:

  • Find a domain name and a web host. Several hosts give you the possibility of having a domain name for free. For example, you can find options for less than $ 3.95 per month online.
  • Choose the solution that interests you for the creation of your website. We will recommend WordPress to you.
  • Create Your Site.

Option 2: Hire a developer

A developer or a web agency can help you develop your website. It can be the best option if you want a quality solution.  Our agency offers you, for example, solutions adapted to your needs at a reasonably competitive cost. If you want to know more about what we offer, visit our services or contact us.

How to Create a YouTube API Key and Retrieve YouTube Channel ID

If you have all the items discussed above, namely a website, a YouTube channel, and a Google cloud account, you can continue with the following.

Create YouTube API Key

It would help if you had the API key to sync your website with YouTube. To get the API key, you need to follow the following steps:

  • First, visit this page
  • Then, in the search field, enter YouTube Data API v3
  • Finally, click on the button activate

Biblothèque des APIs

When you have clicked on activating, the site will generate a code (API) that you will use in the second part.

Retrieve YouTube Channel ID

In order to retrieve the ID of your YouTube channel, you must:

  • Log in to your YouTube account where your channel is located
  • Then In the right corner at the top of the page, click on setting / Configuration
  • In the left menu, click on Advanced Settings/Advanced configuration
  • You will find your login details among the list of other information on the page

Your YouTube channel ID is also on the URL when you follow the steps:

  • Click on your profile picture (in the top right corner) and a drop-down menu will appear
  • Then click on “Your Channel”
  • You will see your channel ID just after youtube.com/channel/ at the URL level

Use the code below to display your videos on your site


<?php
$API_key    = 'xxxx'; // Remplacez par votre clé API
$channelID  = 'xxx';  // Remplacez par votre identifiant Youtube
$maxResults = 10;

// Faire un Appel API pour récuperer la liste des vidéos en format Json
$myQuery = "https://www.googleapis.com/youtube/v3/search?key=$API_key&channelId=$channelID&part=snippet,id&order=date&maxResults=$maxResults";
$ch = curl_init();
    
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $myQuery);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
        
    curl_close($ch);
        
    $data = json_decode($response);
        
   $decoded= json_decode(json_encode($data), true);
 
 
// Run a loop to display list of videos
foreach ($decoded['items'] as $items)
{
$id = $items['id']['videoId'];
$title= $items['snippet']['title'];
$description = $items['snippet']['description'];
$thumbnail = $items['snippet']['thumbnails']['default']['url'];
if(!empty($id)) {
?>
<div class="col-md-4">
    <div class="videoWrap controllles">
                            <img src="<?php echo $thumbnail; ?>" alt="<?php echo $post->post_title; ?>">
                            <div class="play_video">
                                <a class="video_popup" href="<?php echo "https://www.youtube.com/watch?v=".$id; ?>"><i class="fa fa-play"></i></a>
                            </div>
                        </div>
                        <div class="videoblog">
                        <h2><?php echo $title; ?></h2>
                        <p><?php echo $description; ?></p>
                        </div>
</div>
<?php
}
}
?>

Lines 2 and 3 of the code allow you to add your API key and your YouTube ID, respectively. Then line 7 (myQuery) retrieves the YouTube account information using the key and username. All of the following are just codes to browse the data to bring up the list of videos.

Add some CSS to format your page

Add JavaScript to make your page interactive or keep the video playing on your website

Note that the JavaScript code uses jQuery; you must include it in your code if you want to use it.

An alternative in case you use WordPress

We have implemented this tutorial in a WordPress extension; you will find the extension in our extension bank.

How does it work?

After installing the extension, you must:

  • Visit Settings tab ⇾ Vlog Option generator
  • Enter your API credentials and your YouTube channel key
  • The number of data you want to extract
  • The amount of data per page.

Once you save the changes, you can use the shortcodes below to make the videos appear on your website.


Extension pour YouTube

Conclusion

Efficiently managing your YouTube channel on your website can be relatively easy. Thank you for taking the time to read our article. If you have a connection project with APIs to facilitate your daily activities, Contact us.

Leave a comment



Thank you

Thank you for contacting Prositeweb,
Go back to the home page

Please fill free to contact us at any time for any request regarding our services. Contact us.

Thank you