Skip to main content

How to get images from Google Sheets

tip
To enable integration, you can use the ready-made Google Sheets integration block.

In this article, you will learn how to get images from Google Sheets for your scripts so that the images don’t take up space in the script.

You specify images to be displayed on the screen, and you don’t need to add all these images to your script.

Add images to Google Sheets

For example, you have the following spreadsheet with fortunes:

Google Sheets

Image URLs are located in the image column.

caution
URLs must end with .jpg.

Next, you need to publish the spreadsheet and get the URL to access it from the script. To do this, follow the instructions in the Read data from Google Sheets article.

Create a script

  1. Go to Tovie DialogStudio and create a new script.
  2. Add the HTTP request block in that part of the script where you want to get images.
  3. In the URL field, paste the URL that you received in the previous step.
  4. Add two Text blocks for the HTTP request’s outputs.

You will get the following script sample:

Script sample

Add an Image block

  1. Add the Image block to the $prediction.line screen and go to the Using link tab.

  2. In the Enter image URL field, write $prediction.image.

    The Image block

  3. Click Save. Now you can test your script.

Test the script

Click Test at the top of the page.

The bot will display an image that matches a random line received in the HTTP request. Using the $prediction.image variable, we specify the path to the image, while the images themselves are stored in the spreadsheet and do not take up space in the script.