This repo is an adaptation of YouTube API Project With Authentication by Traversy Media.
I followed the tutorial to learn followings:
-
Using YouTube Data API & OAuth2 Login
-
Log in user to YouTube account
-
Enter any channel name to get data
-
Error messages
-
Display channel data
- Channel Title
- Channel ID
- Subscriber count
- View count
- Total video count
- Channel description
- Visit channel button
- Latest videos with thumbnails
-
Pure JavaScript & Materialize CSS used
- Go to Google Cloud Console:
https://console.cloud.google.com/ - Create New Project
- Go to
API & Services>Enable API's & Services - Search for 'youtube data api v3'
- Select
YouTube Data API v3>Enable>Create Credentials - In
Credential Type>Public data>Next - Get your API Key >
Done
- User Type:
External>Create - App information > Add app
Name&Email - Add Application home page URL
- Add developer email address >
Save&Continue Scopes> Save & Continue- Test users > Save & Continue
- Credentials > Create Credentials > OAuth client ID
- Create OAuth client ID > Web Application > Create
- Get Client ID
-
Create
package.jsonfile :npm init -y -
In your package.json, add a start script:
"scripts": {"start": "serve -s ."} -
Add express to
package.json:-
Run
yarn add express -
Ensure express appears under the
"dependencies"section in yourpackage.json."dependencies": {"express": "^4.17.1"} -
Delete the
package-lock.jsonfile.
-
-
Create a
Procfileand add this content :web: node main.js -
Install the Heroku CLI :
- Run :
sudo snap install --classic heroku - Verify Installation:
heroku --version
- Run :
-
Log in to your Heroku account:
heroku login -
Create a Heroku App:
heroku create -
Keep your API key secure:
- Create a
.envfile :API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXX - Add
.envto.gitignorefile so that Git ignores it. - Set your API key as an environment variable in Heroku:
heroku config:set API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXX - Add dotenv to your dependencies:
- Run
yarn add dotenv - If it’s already in devDependencies, move it to dependencies manually in package.json:
"dependencies": {"dotenv": "^10.0.0","express": "^4.17.1"}
- Run
- Create a
-
Deploy to Heroku:
- Remove
node_modules/from.gitignorefile git add .git commit -m "Initial commit for Heroku deployment"git push heroku master
- Remove
-
Add app's URL to the Authorized JavaScript origins list in Google Cloud Console.
- Go to the
Google Cloud Console>APIs & Services>Credentials - Find your
OAuth Client ID> ClickEdit(the pencil icon) - Under
Authorized JavaScript origins, add your Heroku app's URL:https://young-peak-xxxxxxxxxxx-xxxxxxxxxx.herokuapp.com - Save Changes
- Go to the
-
Go to
OAuth consent screen>Publishing status> ChooseBack to TestingorPUBLISH APP -
With the app in
"testing"mode, only users you add in the Google Cloud Console can access it. -
If someone with an email not on the test user list tries to log in, they’ll see an error message stating that they’re not authorized.
-
To allow broader access without this restriction, you would eventually need to re-publish the app to
"production"once you're ready for general access.
-
If you encounter any issues,
- You can check the logs by running:
heroku logs --tail - Clear Build Cache and push again:
heroku repo:reset -a your-app-name - Make sure you're pushing to the correct Heroku remote.
To verify, list your remotes:
git remote -v - Ensure you're on the branch you want to deploy, typically
masterormain
- You can check the logs by running:
-
If Heroku requires you to pull before pushing,
It means your local branch and the remote branch on Heroku are out of sync. If you want to avoid ending up with unwanted pending commits every time, you have two main options:
-
If you’re confident that your local changes should overwrite what’s currently on Heroku, you can force push.
-
This approach is generally safe for a solo project but should be used cautiously if you’re collaborating, as it will overwrite the Heroku branch history.
git push heroku master --force
-
If you prefer a cleaner approach that integrates Heroku’s commits with yours and avoids extra merge commits, use rebase.
-
Rebasing places your commits on top of the Heroku branch, so no unwanted commits are created.
- Fetch Heroku's latest commits:
git fetch heroku - Rebase your local changes onto Heroku's master branch:
git rebase heroku/master - Resolve any conflicts:
git add <file_with_conflict>git rebase --continue - Push your changes:
git push heroku master
- Fetch Heroku's latest commits:
Original tutorial: YouTube API Project With Authentication — Traversy Media.
MIT License