If I make a YouTube video and that video gets more than 2.5M views in just 17 hours, I will get to my rooftops and I will shout about it.
Wait — What if the YouTube video itself can shout for me?
YouTuber Tom Scott’s latest video titled, “This video Has X Views,” will update the title of video with its current View Count. Interesting, right?
Its a really good video, but that video isn’t about the actual code and workflow that does the update of title. In this post, I am going to explain the steps to automatically update the title of YouTube video with the view count using Google Apps Script without any Billing.
Let’s break down the entire process into a few steps. So I know that I want to execute a single script to:
Login to Youtube (with the account that contains the video I want to update )
Get the number of current views of the chosen video.
Update the title of the video with the new information
Run this script as often as I like ( Cron Job )Project start
To fetch the view count of the video, we have to call the YouTube Data API using the video ID. It gives the whole data about the video. We have to take the required data from the result object as below:
getVideoDetails() — This function takes videoId as a parameter and returns details about the video from YouTube using YouTube Data API V3
As the YouTube API Call is limited per day. I recommend adding validation in the code that if the View Count is already the same that in the title. We should not call the Update API. In the below code, it is checking if the view count from the YouTube API is already present in the video title.
validate() — This function validates if the current view count and the count in the title are the same.
Update Info into YouTube
Now, we are at the final step, if the View Count from YouTube is not the same with the count in the title we should update the info back into the YouTube. We use Youtube. Update API from YouTube Data API V3.
updateDetails() — This function updates the info back into the YouTube
Hi, this is Raees Kappoor, Brand Strategist, Advertising Consultant, Digital Marketing Expert & Tech Blogger. We discuss about Digital Marketing Tips Tech tutorials, Apps, Gadgets, How-to and Troubleshooting.