How to automatically update the title of a video with the number of views using YouTube Data API and Deta
- Clone this repo into your machine
- Install Deta CLI and login from your terminal
- Once in the project directory, run
deta new --node youtube-update
- Create a new app in your Google Cloud Dashboard
- Add YouTube Data API v3 to your project
- Create an OAuth Consent Screen and generate a new OAuth credential
- Download the
client_secret.json
file into your project folder - Run
npm install
andnpm run
from your project directory after commenting out the lines regarding importing Deta and setting the cron - This will give you a url in the terminal (as shown in the video given above). Go to this url, paste the code you get back into your terminal.
- Copy the contents of
client_secret.json
and the access tokens you just generated into the code where you use them (again, refer video). - Uncomment the lines for importing Deta and setting the cron
- Run
deta deploy
anddeta cron set "10 minutes"
. This will set the code to run every 10 minutes
Keep in mind that the YouTube API has a daily usage quota of 10000 units. The read and write operation that I have done with this code is worth 57 units. So I can update as frequently as once every 8 minutes before running out of quota for the day. If you set it to run faster, you might get an API quota exceeded error.
You can check the Quota tab in the Google Cloud Dashboard to see your current usage.
For the logs on the server, make sure to check the visor for your project at the Deta Web Dashboard