YouTube API to Google Sheets
Google Apps Script
Key highlights
- Pull YouTube data using the YouTube Data API
- Collate data into Google Sheets
- Collect new data, avoid duplicating old data
- Pull YouTube channel metadata
- Loop through and get all playlists and videos
- Easy configuration by end user
Summary
The project involved pulling information about YouTube channels and their videos and playlists, using the YouTube Data API. A Google Apps Script was built to take an arbitrary number of channel IDs, get their metadata, and then iterate through their videos and playlists and get their own metadata. All information is to be pulled into a Google Sheet.
Easy to use
An instructions tab guides the user on how to configure the Google Apps Script. The instructions show the various data elements pulled for channels, videos, and playlists.
The script can run on a timer, pulling data periodically, or manually via a custom menu item.
Configurable script execution
A configuration sheet is included in the spreadsheet where the user can specify important information for the script. The user supplies the names of the sheets that will house channel, video, and playlist information.
The user supplies the various data elements they want to pull for channels, videos, and playlists. These will appear as metadata columns inside the output sheet.
Finally, the user also enters the series of YouTube channel IDs that the script will run through. This makes it easy to change the data that gets pulled out of the API and where it is stored.
YouTube channel data
When the script runs, it pulls the channel IDs from the Configuration sheet and supplies in this sheet the metadata for each channel.
The metadata is determined based on the columns that the user entered in the Configuration sheet.
YouTube video data
For each channel ID in the configuration tab, the script pulls all the uploaded videos. It then displays the video metadata based on the columns specified in the Configuration sheet.
The script makes subsequent API calls to fetch more videos using "nextPage" tokens, similar to how search result pages work.
The script ensures that each video shows up only once. To improve performance, the script stops pulling video information the moment it encounters an older video that was previously pulled and stored in this sheet.
YouTube playlist data
For each channel ID in the configuration tab, the script pulls all of the channel's playlists. It then displays the playlist metadata based on the columns specified in the Configuration sheet.
The script makes subsequent API calls to fetch more playlists using "nextPage" tokens, similar to how search result pages work.
The script ensures that each playlist shows up only once. To improve performance, the script stops pulling playlist information the moment it encounters an older playlist that was previously pulled and stored in this sheet.