YouTube Video Uploader
This project allows users to upload videos to YouTube using the YouTube Data API v3. It consists of two main parts:
- Index.js: The core script responsible for uploading videos to YouTube once it has the necessary credentials.
-
Server.js: A simple Express server used to obtain the OAuth 2.0 refresh token which can then be used by
index.js
for uploading videos without requiring re-authentication.
Prerequisites
- Node.js installed on your machine.
- A YouTube account.
- A project set up on the Google Developers Console with the YouTube Data API v3 enabled and OAuth 2.0 credentials generated for a web application.
Setup & Installation
-
Clone this repository:
git clone https://github.com/adanzweig/nodejs-youtube.git
-
Navigate to the project directory and install the required npm packages:
cd nodejs-youtube npm install
-
Create a
.env
file in the root directory and populate it with your OAuth 2.0 credentials:CLIENT_ID=YOUR_CLIENT_ID SECRET_ID=YOUR_CLIENT_SECRET REDIRECT_URL=YOUR_REDIRECT_URL # REFRESH_TOKEN will be populated later
-
Run the
server.js
file to start the Express server and obtain the refresh token:node server.js
-
Navigate to
http://localhost:3000/auth
in your browser to start the authentication process. Once authenticated, the refresh token will be displayed in the console. Copy and paste this token into the.env
file as the value forREFRESH_TOKEN
. -
Now that you have the refresh token, you can use
index.js
to upload videos to YouTube:node index.js
Usage
server.js
This file's main purpose is to facilitate obtaining the refresh token. Once you have the refresh token, you don't need to run this file often unless you need a new token.
index.js
Modify the parameters in the uploadVideo
function call at the bottom of the file to fit your video's details. Then, run the script to upload the video to YouTube.
Security
Always ensure that your .env
file is included in your .gitignore
to prevent unintentional sharing of sensitive credentials.