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.

YouTube’s Data API requires authentication for access, through either an API key or OAuth2. The process for getting an API key is rather convoluted, so this article primarily discusses connecting through API Connector’s paid OAuth2 Connection Manager, which handles authentication for you. If you’d prefer to manage the process manually for free, please skip to the Appendix for step by step instructions on connecting with an API key.

CONTENTS

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.

  1. Open up Google Sheets and click Add-ons > API Connector > Manage Connections.
  2. In the list of available connections, find YouTube Data and click Connect.
    youtube-api-img1
  3. You will see a modal asking you to approve the connection. Click Allow.
    youtube-api-img2
  4. You’ll then be returned to your Google Sheet, and can verify that your YouTube Data connection is active in the Connections screen.
    youtube-api-img3

PART 2: CREATE YOUR YOUTUBE API REQUEST URL

We’ll start by following the YouTube API documentation to search 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:

https://www.googleapis.com/youtube/v3/search?part=snippet&q=cats

PART 3: PULL YOUTUBE API DATA INTO SHEETS

We can now enter these values into API Connector and import YouTube data into Google Sheets.

  1. Open up Google Sheets and click Add-ons > API Connector > Open.
  2. In the Create tab, enter the API URL we just created.
    youtube-api-img4
  3. Leave Headers empty as we don’t need them for this request.
  4. Under Authentication, choose YouTube Data from the dropdown menu.
    youtube-api-img5
  5. Create a new tab and click ‘Set current’ to use that tab as your data destination.
  6. Name your request and click Run. A moment later you’ll see some YouTube data populate your spreadsheet:
    youtube-api-img6

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):
    https://www.googleapis.com/youtube/v3/search?part=snippet&q=google sheets&maxResults=50
  • A list of videos in a playlist:
    https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=YOUR_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 list parameter.
    youtube-api-img7

    • A list of videos you’ve liked:
      https://www.googleapis.com/youtube/v3/videos?myRating=like&part=snippet&maxResults=50
    • Key statistics (view counts, video counts, and subscriber counts) for a channel:
      https://www.googleapis.com/youtube/v3/channels?part=statistics&id=YOUR_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/youtube-api-img9
    • Key statistics for multiple channels:
    https://www.googleapis.com/youtube/v3/channels?part=statistics&id=YOUR_CHANNEL_ID1,YOUR_CHANNEL_ID2,YOUR_CHANNEL_ID3...

    (enter your channel IDs as a comma-separated list)
    youtube-api-img10

    HANDLE FILTERING

    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 id parameter:

    https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=qhJOSOBtAlc,4JJd7gmlobY,YVMtL6rexKQ,pJpApDVCXPg,MaeRXppkzdA&fields=items(id),items(snippet(publishedAt,title)),items(contentDetails(duration)),items(statistics(viewCount,likeCount,dislikeCount,commentCount))
    youtube-api-img13

    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 key=YOUR_API_KEY 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.
    1. 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.
      youtube-api-img11
    2. Now in the top left, click Select a Project, which will open up a modal. Click New Project
      youtube-api-img12
    3. 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.
      youtube-api-img13
    4. Once you create your project, click on Credentials in the left-hand menu. Next, click the Create credentials dropdown and click ‘API key’.
      youtube-api-img14
    5. Your YouTube API key is now ready. You’ll see a screen containing your API key; copy this to your clipboard and click Close.
      youtube-api-img15
    6. 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:
      youtube-api-img16
    7. Congrats, you’re done! You now have access to the YouTube Data API, and can start pulling YouTube data into Google Sheets.

16 thoughts on “Import YouTube Data to Google Sheets”

  1. Hi Ana, thank you for this, I managed to set up my API url. how do I get the full url of the Youtube videos into google sheets? sorry completely new to this . I’ve set up an api to search for videos with the keyword podcasting and want to get the full url link of the videos as well as the channel IDs, what do I need to add extra from this: https://www.googleapis.com/youtube/v3/search?part=snippet&key={API_key}&q=google sheets&maxResults=50 ?

    Reply
    • Hey Riva, have you run that search request yet? If so, in the response you should see a field called items » id » videoId. YouTube doesn’t return the full URL, but it’s easy to construct it yourself by adding that value to the YouTube base URL (https://www.youtube.com/watch?v=).
      For example, when I run the search request for ‘podcasting’, in cell J2 under the items » id » videoId header, I see an ID of PIJpOcFf5h4.
      In a new column, I can make a formula like ="https://www.youtube.com/watch?v="&J2 to get the full URL of the YouTube video. Of course you can copy this down or, even better, add it to an array formula like =arrayformula("https://www.youtube.com/watch?v="&J2:J) to get the URLs for all the video IDs returned by the API. Let me know if that makes sense!

      Reply
  2. Will you be adding a walkthrough of how to to set up Youtube Data Api / Analytics for your own channel reports? The documentation has me very confused!

    Reply
    • Hi, yes! I totally understand, Google makes extremely confusing documentation. I added a line on getting data for your own channel, please let me know if that’s what you were looking for.

      Reply
  3. Hi,

    Thanks for detailed documentation. I am new to APIs. So before start implementing this I would like to know if creating project is free or paid service of google? Does it required GSuit?

    Regards,
    Sai Krishna.

    Reply
    • This is free, you don’t need a paid G Suite account to use Google’s APIs. API Connector is free, too (with option for paid upgrade).

      Reply
      • Hi,
        I’m doing a personal project that exceed daily quota.
        Could you please give more information about YouTube API paid option? The only thing I could find on the net is you need to request for additional units.
        Thanks

      • Sorry, I’m not aware of any paid option for the YouTube API. If you haven’t seen it already, this page describes how to check your quota usage and contains a link to the form where you can request a quota increase. This article also contains info on requesting an increase.

  4. Hi,

    For a noob like me this page is very obscure, I don’t really understand what the end result is, but it looks like it’s close to what I’m looking to achieve.

    I found this page because I want a Google sheet to update the subscriber count of my YouTube channels daily (I am the owner of those channels).

    The thing is I want that Google Sheet to update daily without me manually opening it (so I can analyze the data with graphs)

    Right now, I have a clunky solution that uses IMPORTXML in a cell and targets socialblade.com to gather different metrics and a daily google script creates a line every day with the information on that sheet.
    Problems:
    – I’d rather get that data directly from YouTube and not a 3rd party site
    – IMPORTXML doesn’t update if I don’t manually open the Google sheet…

    Any help is appreciated!

    Reply
    • Hi Tristan, thank you for the message and sorry if the article was confusing. Please see below.

      I don’t really understand what the end result is
      There are a few screenshots in the article, for example the final screenshot of part 3 shows the result of a query for a list of videos, and the screenshot at the very end shows the end result of a query for likes, views, and comments. Does that help or are you looking for a screenshot of something in particular?

      I want that Google Sheet to update daily without me manually opening it
      The method in the article is free to run manually, but automatic daily updates requires the paid version of API Connector. Not sure if you were looking for a totally free solution or not.

      I’d rather get that data directly from YouTube and not a 3rd party site
      Yep, this method pulls directly from YouTube’s official API, so it’s all above board and reliable.

      Happy to answer any further questions so just let me know what you’re looking for.

      Reply
      • Thanks for your answer, I guess the confusing thing is that you seem to be focused on pulling data for videos, when the first need – at least in head – would be to pull data for the channel (things like subscriber count, watch time in different period of time, number of uploads, etc).
        After having those channel metrics covered, I understand that to get more granular some would want to go on the video level.

        My current need is to have a daily automatic scrape of my YouTube channels and reporting in google sheet automatically without having to open the sheet itself.
        So when you go on that sheet every month or so, it’s all populated and graphs are telling you the evolution of those channel metrics…

        I can’t find a simple solution anywhere…

      • You can get channel data as well as video data through the YouTube Data API, you can find examples of both in the article. Though if you want detailed private data (data that you can only see while logged in) about your account like watch time and number of uploads, you would need to use the YouTube Analytics API instead. I think you can manage the solutions in either of these guides if you try, since ultimately you just need to follow the steps and copy/paste in a URL at the end. It doesn’t require writing code or any particular tech skills. But if you aren’t comfortable with that, I suggest using a different tool like Supermetrics. They simplify the connection process even further so you can just select your metrics from a drop down menu instead of working with the API directly.

  5. OK, I’m not a coder, half the things you mentioned are foreign and not understood, but I am a marketer and I know there is a need.

    In this time of let-me-write-a-blog-to-bring-value-when-the-only-thing-I-really-want-is-organic-exposure I am stunned that my simple need (which is every serious YouTuber need) isn’t answered.

    I went through many many sites, and everything is wordy and confusing.

    YouTubers need to see the history of how they’re doing to decide on what to do next.
    We need to see the subscriber count growth, we need to see the watch time evolution and many other things but that’s a start.

    Anybody reading those lines: there is an obvious need for YouTubers to have an automatic report on google sheet. It looks like it should be a piece of google script. So if you explain how to do it, you would have great traffic on your page.

    Just my 2 cents

    Reply
    • Hi Tristan, thanks for the feedback. Please check my last response to you as it includes the name of a tool that imports YouTube data without needing to copy/paste a URL like the method in this article.

      Reply
  6. How do I return the first result for say 50 different youtube searches in one go? E.g query one would be “manchester united football”, query two would be “chelsea football club” and so on.

    Reply

Leave a Comment