Import YouTube Data to Google Sheets
YouTube provides a Data API, a Reporting API, and an Analytics API, all with different but overlapping functionality. In this guide, we’ll be looking at the Data API, which provides basic video and channel statistics for all public videos and channels, and enables access through a simple API key (the other APIs require OAuth2 authentication and only show statistics for your own videos). In this guide, we will walk through how to pull data from the YouTube Data API directly into Google Sheets using the API Connector add-on for Sheets. We’ll first get an API key from YouTube, and then set up a request to pull in video details and metrics from YouTube to your spreadsheet.
- Part 1: Get your YouTube Data API Key
- Part 2: Create your API Request URL
- Part 3: Pull YouTube API Data into Sheets
- Part 4: More Example API URLs
- Part 5: Handle Filtering
YouTube requires that all API requests contain an API key. This is the detailed, step-by-step process to get your YouTube API key:
- Navigate to https://console.developers.google.com/. If this is your first time accessing this page, you’ll be prompted to accept Google Cloud Platform’s terms of service. Click agree and continue.
- Now in the top left, click Select a Project, which will open up a modal. Click New Project
- This will open up the New Project modal. You can name your project anything, but let’s call it YouTube API. You’ll also be prompted to browse for a Location (aka folder). For our purposes here, it doesn’t matter which one you pick.
- Once you create your project, click on Credentials in the left-hand menu. Next, click the Create credentials dropdown and click ‘API key’.
- Your YouTube API key is now ready. You’ll see a screen containing your API key; copy this to your clipboard and click Close.
- There’s still one last step: you need to enable the YouTube API in your project. To do this, click Library and search for ‘YouTube Data API’. Alternately, you can navigate there directly with this link: https://console.developers.google.com/apis/library/youtube.googleapis.com. Click Enable as shown:
- Congrats, you’re done! You now have access to the YouTube Data API, and can start pulling YouTube data into Google Sheets.
- API root: https://www.googleapis.com/youtube/v3
- Endpoint: /search
- Parameters: ?part=snippet&key=YOUR_API_KEY
Parameters Example: ?part=snippet&key=12345
Putting this all together, we get the full API Request URL:
Where it says YOUR_API_KEY, you’ll need to substitute your actual API key from part 1 (step 5) above.
We’re now ready to enter all our values into API Connector and import YouTube data into Google Sheets:
- Open up Google Sheets and click Add-ons > API Connector > Create New API Request
- In the Create Request interface, enter the Request URL we just created:
- Leave Headers empty as we don’t need them for this request. We don’t need authentication either, so just leave that as “None”.
- Create a new tab. You can call it whatever you like, but here we’ll call it ‘YouTube’. While still in that tab, click ‘Set’ to use that tab as your data destination.
- Name your request. Again we’ll call it ‘YouTube’
- Click Run and a moment later you’ll see some YouTube data populate the YouTube tab:
PART 4: MORE EXAMPLE API URLs
- Now that the basic Request URL is set up, you can modify it using parameters listed in the documentation. For example, you may want to change the number of results to 50 (default is 5) and search for videos related to a specific query string, say ‘google sheets’. You’d do that using the parameters ‘maxResults’ and ‘q’, creating the following request URL:
- To see a list of all the videos in a playlist, change the API URL path to include the playlistId parameter:
You can find your playlist ID by clicking into a YouTube video in your playlist and checking the URL. It will be located inside the
- To see statistics like views and subscribers for your own channel (or any public channel), first get the channel ID by hovering over or clicking on the channel name listed under any video, and checking the text in the URL after /channel/
Next, substitute that channel ID into the following URL and paste into API Connector. Click Run to see stats about the channel like view counts, video counts, and subscriber counts.
If you want to query multiple channel IDs, just enter them as a comma-separated list, e.g.
You can filter your results using the “fields” parameter as described here: https://developers.google.com/youtube/v3/getting-started. For example, this filtered URL will produce a list of metrics like video titles, view counts, like counts, dislike counts, etc. for all the video IDs listed in the
key=YOUR_API_KEY. You may find it convenient to reference your key from your sheet using +++ syntax, as shown in the screenshot above (info).