Search API Connector Documentation
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.
- Before You Begin
- Part 1: Set up your Google Cloud Project
- Part 2: Get your Cloud Vision API Key
- Part 3: Pull Cloud Vision Data into Sheets
- Part 4: Get More Cloud Vision API Data
- Part 5: API Documentation
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Set Up Your Google Cloud Project
- While logged into your Google account, navigate to https://console.developers.google.com/ and click Select a project.
- 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.
- You'll now see a screen asking you to name your project. We'll call it 'Cloud Vision'. Click Create.
- 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:
Part 2: Get Your Cloud Vision API Key
- From the dashboard, click Enable APIs and Services.
- Use the search box or scroll down the page to find 'Cloud Vision API'. Click to select it.
- On the Cloud Vision API details page, click Enable.
- Back on the dashboard, choose Credentials from the menu.
- Click +Create Credentials and select API key from the dropdown menu.
- 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).
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.
- Open up Google Sheets and click Extensions > API Connector > Open > Create request.
- In the request form enter the following:
- Request URL:
- Request body:
- Create a new tab and click Set current to use that tab as your data destination.
- 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.
- Name your request and click Run. A moment later you’ll see an analysis of your image in Google Sheets:
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 ImgURL
I can now reference it by substituting in
+++ImgURL!A1+++instead of the full URL:
- If you want to analyze multiple images in a single call, add them into the 'requests' array like this:
LABEL_DETECTION, you can try
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