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: Fetch Public Data from YouTube
- Part 3: Create a Custom API Request
- Part 4: Handle Filtering
- Part 5: Handle Pagination
- Part 6: YouTube Compliance
- Part 7: 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
The easiest way to get started with the YouTube Public Data API is through API Connector’s built-in integration.
- Select YouTube Public Data from the drop-down list of applications
- Under Authorization, click Connect to YouTube Public Data
- 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.
Part 2: Fetch Public Data from YouTube
Now that we’re connected, let’s pull some data into Sheets.
- Under Endpoint, choose the data you’d like to retrieve. We’ll start with
- Fill in any required parameters. For the
/channelsendpoint we need to populate the
idparameter with at least one channel ID.
- To get a channel ID, visit the channel page on YouTube, right-click > View Page Source, and search for
https://www.youtube.com/channel/in the page source. The channel ID will appear directly after the
- Optionally set any optional parameters, such as
maxResultsto get more records, or
partto select which data points should be included in the response.
- Select a destination sheet, name your request, and click Run.
Part 3: Create a Custom API Request
Alternatively, you can create a custom request instead of using API Connector’s built-in integration. When you create a custom request, you add your complete URL into the API URL field and select YouTube from the OAuth menu.
To easily convert your preset request to a custom request, click Output Options > More Options > Add Request URL. This will print your URL into your sheet where you can copy it.
Part 4: Handle Filtering
When creating custom requests, 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 5: Handle Pagination
By default YouTube limits the number of results in a single response to 5 rows, which can be increased to by setting the
maxResults parameter to 50. 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:
- Pagination type:
- Next token parameter:
- Next token path:
- Run until: choose when to stop fetching data
Part 6: 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 7: 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 custom 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.