Welcome folks today in this blog post we will be uploading video from google drive
to youtube
using google apps script in javascript. All the full source code of the application is shown below.
Get Started
In order to get started you need to make a new google apps script
project and copy paste the code inside the code.gs
file as shown below
code.gs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function uploadToYoutube(){ const sourceFile = DriveApp.getFileById("##googledrivevideoid##").getBlob(); const videoResource = { snippet: { title: 'Summer vacation in California', description: 'Had a great time surfing in Santa Cruz', tags: [ 'surfing', 'Santa Cruz', ], categoryId: '22', }, status: {privacyStatus: 'private'} // Added }; const newVideo = YouTube.Videos.insert( videoResource, "snippet,status", sourceFile); // Modified console.log(newVideo) } |
As you can see we are making the function
which takes the video from the google drive and take it’s video id and upload it to youtube as a private video and also we are setting the basic information about the video such as the title and description using the drive and youtube api. For this you need to to drive and select the video you want to upload and then get it’s shareable link and from that you need to copy paste the video id and paste it in the above script. The process is shown below
Enabling the Google Drive and Youtube Services
Now we also need to enable the google drive and youtube api services. At the left hand side you will find the section of services we need to click on that as shown below
Now you just need to run the method
to execute the script which will automatically fetch the google drive video and upload it to youtube as a private video