Print

Import Google Cloud Vision API Data to Google Sheets

In this guide, we’ll walk through how to use the Cloud Vision REST API directly from Google Sheets with just an API key, using the API Connector add-on for Sheets.

Google's Cloud Vision API uses machine learning and AI to automatically classify images and detect objects like faces and landmarks, so it's a pretty cool API to dig into. We'll first set up our project, then get the API key from Google, and then set up a request to analyze images in our spreadsheet.

Contents

Before You Begin

Click here to install the API Connector add-on from the Google Marketplace.

Part 1: Set Up Your Google Cloud Project

  1. While logged into your Google account, navigate to https://console.developers.google.com/ and click Select a project.
    google-cloud-vision-img1
  2. A modal will appear, prompting you to choose an existing project or create a new one. You can do either, but here we'll create a new one by clicking New Project.
    google-cloud-vision-img2
  3. You'll now see a screen asking you to name your project. We'll call it 'Cloud Vision'. Click Create.
    google-cloud-vision-img3
  4. Before we move on, you'll need to set up billing. A billing account is required in order to use Cloud Vision API, but you won't need to pay unless you use more than 1000 'units' in a month. Pricing details are listed here, and billing can be enabled by following the instructions here. If this is your first time setting up billing on a project, you'll likely be offered a free credit:
    google-cloud-vision-img13

Part 2: Get Your Cloud Vision API Key

  1. From the dashboard, click Enable APIs and Services.
    google-cloud-vision-img4
  2. Use the search box or scroll down the page to find 'Cloud Vision API'. Click to select it.
    google-cloud-vision-img5
  3. On the Cloud Vision API details page, click Enable.
    google-cloud-vision-img6
  4. Back on the dashboard, choose Credentials from the menu.
    googlecloudvision-credentials
  5. Click +Create Credentials and select API key from the dropdown menu. googlecloudvision-apikey
  6. Congrats, you have your Google Cloud Vision API key! Copy this and keep it safe, we'll need it shortly. You can also restrict your key via this page, to prevent unauthorized use (recommended).
    googlecloudvision-apikey-copy

Part 3: Pull Google Cloud Vision API Data into Sheets

For this example, we'll run annotation and detection for this image from Wikipedia. Substitute in your own API key where it says your_api_key, and your own image URL, if you like.

  1. Open up Google Sheets and click Extensions > API Connector > Open > Create request.
  2. In the request form enter the following:
    • ApplicationCustom
    • MethodPOST
    • Request URLhttps://vision.googleapis.com/v1/images:annotate?key=your_api_key
    • Headers:
      • Content-type: application/json
    • Request body: {"requests":[{"image":{"source":{"imageUri":"https://upload.wikimedia.org/wikipedia/commons/4/41/Sunflower_from_Silesia2.jpg"}},"features":[{"type":"LABEL_DETECTION","maxResults":10}]}]}
  3. Create a new tab and click Set current to use that tab as your data destination.
  4. Under Output Options, change the report style from 'default (single row)' to 'grid'. For this API response, the output is more readable on separate rows. You can read more about report styles here: Report Styles.
    googlecloudvision-grid
  5. Name your request and click Run. A moment later you’ll see an analysis of your image in Google Sheets:
    googlecloudvision-response

Part 4: Get More Cloud Vision API Data in Sheets

  • If you'd like to analyze URLs more conveniently, you can use cell values in the request body. For example, here I've added the URL to cell A1 in the sheet ImgURLgoogle-cloud-vision-img18

     I can now reference it by substituting in +++ImgURL!A1+++ instead of the full URL:


    google-cloud-vision-img19

  • If you want to analyze multiple images in a single call, add them into the 'requests' array like this: {"requests":[{"image":{"source":{"imageUri":"+++ImgURL!A1+++"}},"features":[{"type":"LABEL_DETECTION","maxResults":5}]},{"image":{"source":{"imageUri":"+++ImgURL!A2+++"}},"features":[{"type":"LABEL_DETECTION","maxResults":5}]}]}
  • Besides LABEL_DETECTION, you can try FACE_DETECTION, WEB_DETECTION, IMAGE_PROPERTIES, LANDMARK_DETECTION, and so on.

Part 5: API Documentation

Official API documentation: https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate

Official how-to-guides: https://cloud.google.com/vision/docs/how-to

2 thoughts on “Import Google Cloud Vision API Data to Google Sheets”

  1. Could you reference where we could scan a google drive folder? Looking to analyze 1000+ images for text and looking how to do this.

    Reply
    • Hey Nik, the end of the article shows how to analyze multiple images in a single call. I believe your Google Driver folder would need to be public.

      Reply

Leave a Comment

Jump To