Search API Connector Documentation
Import YouTube Public Data to Google Sheets
In this guide, we’ll walk through how to pull public video data like views, comments, and likes from the YouTube Public Data API directly into Google Sheets using the API Connector add-on for Sheets.
There are 2 ways to connect to the YouTube Public Data API:
- Preset “Connect” button (OAuth) premium
- Personal API key. Please check the appendix for detailed instructions to retrieve your key.
Import Private YouTube Analytics Data to Google Sheets
- Before You Begin
- 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
- Part 6: Handle Pagination
- Part 7: YouTube Compliance
- Part 8: API Documentation
- Appendix: Connect with a YouTube Data API Key
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
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 Extensions > API Connector > Manage Connections.
- In the list of available connections, find YouTube and click Connect.
- You will see a couple of screens asking you to log in and 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
We’ll start by searching for some cat videos using the “search” endpoint.
- 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
Now let’s enter those values into API Connector.
- Open up Google Sheets and click Extensions > API Connector > Open.
- In the Create tab, enter the API URL we just created.
- Under Authentication, choose YouTube from the dropdown menu. You should see a “Connected” badge.
- We don’t need any Headers so just skip that section.
- 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
YouTube provides a huge number of different data points and functionality in their API. I’ve tried to give a lot of examples and summarize the most useful endpoints below, but for more complete information, please check the full YouTube documentation here.
These sample URLs can also be accessed via API Connector’s API Library (just search for “YouTube” while in the add-on).
- A list of 50 videos matching a search string (default is 5 results):
- A list of videos in a playlist (substitute in your own playlist ID):
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 (views, likes, dislikes, comments) for a list of videos (substitute in your own video IDs):
- Key statistics (view counts, video counts, and subscriber counts) for a channel (substitute in your own channel ID):
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)
Part 5: Handle Filtering
You can filter your results using the “fields” parameter as described here. 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
If you’re using pagination handling, please make sure your field list includes
You can also filter data through API Connector’s visual field editor (just click Edit Fields to enter).
Part 6: Handle Pagination
By default YouTube limits the number of results in a single response to 5 rows, which can be increased to 50 by adding
&maxResults=50 to the end of your API request URL.
If you want to retrieve more than 50 results at a time, you’ll need to traverse the paginated results as described here.
This can be handled automatically by API Connector through the pagination handling feature, like this:
- API URL: enter your request URL, including &maxResults=50
- Pagination type:
- Next token parameter:
- Next token path:
- Run until: choose when to stop fetching data
Part 7: YouTube Compliance
To comply with the terms of YouTube’s API, requests using API Connector’s YouTube OAuth connection are subject to the following conditions:
- All saved requests to YouTube will refresh every 30 days, even if you have not set up a scheduled refresh.
- All YouTube requests will show only the metric name rather than the full path in the header row.
“API Clients may store all other types of Authorized Data not identified in section (III.E.4.b) for as long as is necessary for the purposes of the specific consent granted by an active user and for no longer than 30 calendar days. After 30 calendar days, the API Client must either delete or refresh the stored data”. (link)
Part 8: API Documentation
Official API documentation: https://developers.google.com/youtube/v3/docs/search/list
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:
- 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 can use this token by appending
key=YOUR_API_KEYto 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.