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 video and channel statistics for all public videos and channels. We will walk through how to pull video data from the YouTube Data API directly into Google Sheets using the API Connector add-on for Sheets.
YouTube’s Analytics API, which provides detailed private data about your account (i.e. data you need to be logged in to view) is discussed in a separate article.
- Part 1: Connect to the YouTube Data API
- 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
- Appendix: Connect with a YouTube Data API Key
PART 1: CONNECT TO THE YOUTUBE DATA API
If you haven’t connected to the YouTube Data API before, you’ll first need to initiate the connection.
- Open up Google Sheets and click Add-ons > API Connector > Manage Connections.
- In the list of available connections, find YouTube Data and click Connect.
- You will see a modal asking you to approve the connection. Click Allow.
- You’ll then be returned to your Google Sheet, and can verify that your YouTube Data connection is active in the Connections screen.
PART 2: CREATE YOUR YOUTUBE API REQUEST URL
- API root: https://www.googleapis.com/youtube/v3
- Endpoint: /search
- Parameters: ?part=snippet&q=cats
Putting this all together, we get the full API Request URL:
PART 3: PULL YOUTUBE API DATA INTO SHEETS
We can now enter these values into API Connector and import YouTube data into Google Sheets.
- Open up Google Sheets and click Add-ons > API Connector > Open.
- In the Create tab, enter the API URL we just created.
- Leave Headers empty as we don’t need them for this request.
- Under Authentication, choose YouTube Data from the dropdown menu.
- Create a new tab and click ‘Set current’ to use that tab as your data destination.
- Name your request and click Run. A moment later you’ll see some YouTube data populate your spreadsheet:
PART 4: MORE EXAMPLE API URLs
You can experiment with endpoints and query strings as described in the documentation to see other types of YouTube data, but if you just want to jump in and get a feel for it, play around with the URLs you enter in the API URL path field. Try the following (one at a time), substituting in actual values where indicated.
- A list of 50 videos matching a search string (default is 5 results):
- A list of videos in a playlist:
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
- A list of videos you’ve liked:
- Key statistics (view counts, video counts, and subscriber counts) for a channel:
To get the channel ID, hover over or click the channel name listed under any video, and check the text in the URL after /channel/
- Key statistics for multiple channels:
(enter your channel IDs as a comma-separated list)
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
APPENDIX: CONNECT WITH A YOUTUBE DATA API KEY
YouTube requires that all API requests are authenticated. This is the detailed, step-by-step process to authenticate with a YouTube API key:This section is provided as an alternative to the method described above. Instead of clicking YouTube Data in the Connections manager, you will retrieve your key yourself. Once you have it, you can use it by appending
to any API URL, e.g.
https://www.googleapis.com/youtube/v3/search?part=snippet&q=cats&key=YOUR_API_KEY. Since you’re manually including an API key, leave OAuth2 authentication set to None.
- 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.
- A list of videos you’ve liked: