Import The Movie Database (TMDb) Data to Google Sheets

Table of Contents

Import The Movie Database (TMDb) Data to Google Sheets

In this guide, we’ll walk through how to pull movie and tv data from the community-driven site known as The Movie Database (TMDb) directly into Google Sheets, using the API Connector add-on for Sheets. We'll first get an API key from TMDb, and then set up a request to pull in movie data to your spreadsheet.

STEP 1: GET YOUR TMDb API KEY

  1. If you haven't already, sign up for an account at https://www.themoviedb.org/account/signup
  2. While logged in, navigate to your account settings page and then click "API". Alternately, you can click this link to go there directly: https://www.themoviedb.org/settings/api
    tmdb-img1
  3. Generate a new API key by clicking the link in the "Request a new API key" section:
    tmdb-img2
  4. You'll be prompted to select the appropriate type of API key for your project:
    tmdb-img3
  5. Read and accept the terms of use.
    tmdb-img4
  6. You will be asked to describe how you will use the API data you retrieve. While we aren't exactly making an app, fill out all required fields as best as possible and click submit.
    tmdb-img5
  7. A new screen will appear showing your API keys. Congrats, you now have access to the TMDb API! Note that you can use either the API Key (v3 auth) or API Read Access Token (v4 auth) key for making requests to the API. However, since the v4 authentication method is newer and can be used across both API versions, this tutorial will use the v4 auth key.
    tmdb-img6

STEP 2: CREATE YOUR TMDb API REQUEST URL


We’ll first follow the TMDb API documentation to get a ranked list of the top rated movies on TMDb.

  • API root: https://api.themoviedb.org
  • Endpoint: /3/movie/top_rated

Putting it all together, we get the full API Request URL:

https://api.themoviedb.org/3/movie/top_rated

STEP 3: PULL TMDb API DATA INTO SHEETS


We can now enter all our values into API Connector and start importing TMDb data into Google Sheets.

  1. Open up Google Sheets and click Add-ons > API Connector > Create New API Request.
  2. In the Create Request interface, enter the Request URL we just created
    tmdb-img7
  3. Under Headers, enter two sets of key-value pairs like this:
    AuthorizationBearer YOUR_API_READ_ACCESS_TOKEN
    Content-Typeapplication/json;charset=utf-8

    Replace YOUR_API_READ_ACCESS_TOKEN with the read access token you got above in part 1, step 7.
    tmdb-img8

  4. Create a new tab. You can call it whatever you like, but here we'll call it 'Top Rated'. While still in that tab, click 'Set' to use that tab as your data destination.
  5. Name your request. Again we'll call it 'Top Rated'
  6. Click Run and a moment later you’ll see a list of top rated movies populate your Google Sheets.
    tmdb-img9

STEP 4: GET MORE DATA & HANDLE PAGINATION

  1. You can check the documentation for the full list of available API requests,  but if you just want to jump in, you can play around with the URLs you enter in the API URL path field. Try the following (one at a time):
    https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc
    https://api.themoviedb.org/3/discover/movie?primary_release_year=2020&sort_by=vote_average.desc
    https://api.themoviedb.org/3/discover/tv?with_genres=18
    https://api.themoviedb.org/3/genre/movie/list
    https://api.themoviedb.org/3/trending/all/week
    https://api.themoviedb.org/3/search/keyword?query=parasite
  2. Note that the TMDb API limits the number of records returned in each request. By default, only the first page of records will be returned unless you use the 'page' parameter, and each page contains 20 records. To access more than 20 records, edit the "page" parameter to your URL path, like this:
    page 1: https://api.themoviedb.org/3/movie/top_rated?page=1
    page 2: https://api.themoviedb.org/3/movie/top_rated?page=2

    With API Connector, you can either set these up as separate requests or loop through them automatically with pagination (paid feature) for added efficiency, like this:
    quaderno-img7

  3. IMPORTANT SECURITY NOTE

    Anyone with Owner or Edit access to your Google Sheet can view all the information you've saved within API Connector, including API keys and other credentials. Treat these keys as passwords and limit access to your sheet accordingly.

Comments:0

Leave a Reply

Your email address will not be published.