Our Biggest Sale Is Here
Up to 70% Off
Get the Deal

How to connect wpDataTables with the Google Sheets API

Say your sales figures live in a private Google sheet that you don’t want to publish to the web, and your site’s table has to show every change right away. Connecting wpDataTables to the Google Sheets API solves both: wpDataTables reads the sheet through a Google service account, so the sheet can stay private, and changes show without Google’s 15-minute cache. You set up the account in Google Cloud once and paste its key into wpDataTables.

What do I need to connect the Google Sheets API?

You need a Google account that can create a project in the Google Cloud console, and about 10 minutes. The setup has four parts:

  1. A Google Cloud project with the Google Drive API and Google Sheets API turned on.
  2. A service account in that project, with a JSON key.
  3. The key pasted into wpDataTables → Settings.
  4. Each private sheet shared with the service account’s email.

The free Google Sheets API has usage limits. For busy pages, turn on caching with auto update, so the table calls Google on a schedule instead of on every visit.

How do I set up the project in Google Cloud?

Create a project, turn on the two APIs and create a service account with a JSON key, all in the Google Cloud console.

  1. Create a project. Open the Google Cloud console, click Select a project → New Project, enter a Project name, for example wpdatatables-sheets, and click Create. Then pick the new project in the project list at the top.
  2. Turn on the Google Drive API. Go to APIs & Services → Library, open Google Drive API and click Enable.
  3. Turn on the Google Sheets API. Go back to Library, open Google Sheets API and click Enable. Check that both APIs appear in Enabled APIs & services.
  4. Create the service account. Go to IAM & Admin → Service accounts and click + Create service account. Enter a Service account name; the Service account ID and email address fill in by themselves. Click Create and close. You can leave the optional Permissions and Principals with access steps empty.
  5. Create the key. Open the new service account, go to the Keys tab, click Add key → Create new key, keep the Key type JSON and click Create. Google downloads a .json file to your computer and shows Private key saved to your computer.
The Keys tab of a Google Cloud service account with the Add key menu open on Create new key and the Create private key dialog with JSON selected
Creating the service account key, shown as overlapping panels: (1) the Keys tab, (2) Add key and Create new key, (3) Key type JSON, (4) Create.

The JSON file is a private key. Don’t share it, don’t upload it to the Media Library, and delete the downloaded copy after you paste it into wpDataTables.

Where do I paste the service account key in wpDataTables?

Paste the whole content of the JSON file in Google service account data on the Google Spreadsheet API settings tab and click Validate & Save.

  1. Copy the key. Open the downloaded .json file in a text editor and copy all of its content.
  2. Open the settings. Go to wpDataTables → Settings and open the Google Spreadsheet API settings tab.
  3. Paste and validate. Paste the content in Google service account data and click Validate & Save.
  4. Check the connection. When the key is valid, the tab shows Your Google service account: with the service account email. You’ll need the email for private sheets.
The Google Spreadsheet API settings tab in wpDataTables settings with a connected Google service account and the Remove account button
A connected service account: (1) the Google Spreadsheet API settings tab, (2) your Google service account (email blurred), (3) Remove account.

To disconnect the account, click Remove account. Tables that read private sheets stop working until you connect an account again.

How do I create a table from a private Google sheet?

Share the sheet with the service account email, then create the table with the link from your browser’s address bar.

  1. Copy the email. Copy the email after Your Google service account: from the Google Spreadsheet API settings tab.
  2. Share the sheet. In Google Sheets, open the sheet and click Share. Paste the email in Add people, groups, spaces, and calendar events.
  3. Choose the role. The role list next to the email starts at Editor. Choose Viewer, which is enough for reading the sheet.
  4. Skip the notification. Clear Notify people. The Send button changes to Share; click it. The service account can now read the sheet, and the sheet stays private for everyone else.
  5. Create the table. Copy the sheet’s link from the address bar and use it to create a table from Google Sheets. You don’t need to publish the sheet.
The Google Sheets Share dialog with the service account email (blurred) added as Viewer and Notify people unchecked
Sharing a private sheet: (1) the service account email (blurred), (2) Viewer, (3) Notify people unchecked, (4) Share.

Tables linked to sheets you already published also use the API once it is connected, so they update without the 15-minute delay.

What should I remember about the Google Sheets API?

Create a Google Cloud project, turn on the Google Drive API and Google Sheets API, create a service account and download its JSON key. Paste the key in Google service account data in wpDataTables → Settings → Google Spreadsheet API settings and click Validate & Save. Share private sheets with the service account email, keep the key private, and cache busy tables to stay within Google’s limits.

Wait, Before You Download!

To get your hands on wpDataTables Lite, please enter your email address below. We’ll send you a direct download link and keep you updated on existing features along with helpful tips and tricks!

By continuing, I accept Privacy Policy and T&C
Mail Box