How to Get your YouTube last video uploaded with Google API

THIS IS A TUTORIAL FOR GET YOUR OWN COMMAND OF:
- Get your last video uploaded to YouTube
command

Things before to start:
1.- This link is actually generated by Google to get a JSON from a query(search) on YouTube:

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=CHANNEL_ID&maxResults=1&order=date&type=video&fields=items.id.videoId&key=USER_API_KEY

Let me explaint important parameters:
channelId=CHANNEL_ID - This URL Parameter is the channel ID, you can get it from here:
> See your YouTube Channel ID here
image
key=USER_API_KEY - This is your API Credential Auth, You can get it from your developer account of Google in this link:
> Get Your Credential Here
image

2.- After knowing the above URL, and get both (ID and API key) you need to check the URL with your information:
- Simply replace parameter value from key and channelId.

This could happen

To fix this you have to go to the link that this page refers to and enable YouTube API
image

Then your link will work:
image
The most important thing we need from this JSON is the videoId value so…

3.- Shorten our JSON link

  • We have to shorten our JSON link first:
    I recommend this shortener
    image
    (for testing reasons my link was changed before)

  • After getting our JSON shortened link we have to make the next step:

4.- Creating the Nightbot command

!addcom !video $(eval const urlJSON = '$(urlfetch json YOUR_LINK )'; 
const j = JSON.parse(urlJSON); 
const json = j.items[0].id.videoId; 
"/me Heyo! VoHiYo This is my last video from youtube, check it out! http://y2u.be/" + json)

YOUR_LINK - change it for your link

5.- Enjoy!

That was all! This command get your last video from youtube so, no neccesary updates to the command.
Good luck for everybody :smiley:

1 Like

$(urlfetch https://decapi.me/youtube/latest_video?id=CHANNEL_ID)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.