Automatic Screenshot in Google Sheets

Learn how to automate screenshot capturing in Google Sheets using the Screenshot One API. This tutorial covers setting up the API, creating functions to grab screenshots, and saving them to Google Drive on a scheduled basis.

So let's create automatic screenshots. In our Google sheets, so we can select URLs and get that screenshot. We're gonna use screenshot one.com. It has a hundred free API calls, I believe. Um, and there's a lot of reasons we will do this. One, maybe we want to create our own archive of a particular page, like. Front page is better sheets.co. And yes, I can go to like internet archive and see the past results, but for some marketing purposes or quick screenshots, maybe I want to screenshot it every week because I'm doing some kind of experiment or I wanna look at competitor pricing. Um, I'm gonna look at their pricing page. I want to screenshot of that. I wanna save that screenshot. Maybe I want to.

Analyze it later or grab it each week and just have it available. Or I wanna look at like Google search results and see exactly what's going on. Not just scrape the results, but literally see, okay, go to the page, see the results, see if there's AI stuff going on. I wanna like look at it. Or I even wanna like screenshot a Google sheet, for example. Anywhere where you can go to the URL, you can grab a image of that. Page and you wanna save it. This is going to be a very helpful tutorial for you. Uh, we're gonna actually do two things in this video. We are going to grab the screenshot, which I've made a video of this before, exclusive to members, but now I'm going to try to automate this because I want to

say, Hey, go to this webflow.com/pricing every week, once a week at the exact same time, and grab a screenshot and save all of those into a. Drive. All right. We are going to start from blank. We are going to try to just get the screenshot using this screenshot, API, screenshot one API. You need to go to screenshot one. You need to go and get your access key. That is all you need from screenshot one. Everything else will be in this video, so we're gonna call this auto screenshot. I am gonna create a function called get screenshot. I'm gonna go to some Target URL because we, we, you're

gonna use a few different URLs. I wanna say, what is the website's URL that we're actually gonna get the screenshot of? We're gonna need the A-P-I-U-R-L. We're gonna need the URL of the actual cached image . Uh, we're gonna end up at the end with some kind of URL for even the. Google drive saved image . So this target URL is called target, URL, not just URL. Above this as a blanket sort of overall variable. I'm gonna write API key and you put your API key here. I'm putting mine and I, of course I'm gonna regenerate mine after I make this video. But you just put yours there in quotes and all caps, API key, we can now use that anywhere in our function as a variable.

I just wanna make that clear that this is where you can edit this. If you are a better Sheets member and you're watching this on better Sheets, this sheet exactly, the sheet is down below. You can just copy it and use it and edit it as you wish. So we're gonna need the A-P-I-U-R-L, and this is going to be HTPs back slash back slash api. Screenshot one.com/take. That's the entire A-P-I-U-R-L, and then we're going to need to encode this. The reason is we want to make it so that we can actually access it through URL fetch app. Like it's an, like, if we write some spaces here or things they're

gonna, we wanna change them into literally A URL can use that letter. So we're gonna say encode encoded, URL. Equals encode URI component and put our target URL here, so the URL that we're grabbing from our sheet, just in case it's oddly, maybe we're copy and pasting it from somewhere. We just wanna make sure that it is correctly accessible to put into a URI or URL. And now we are going to take this A-P-I-U-R-L, our target URL, and we're gonna combine them into a single URL that that then we can use URL

fetch app to go and get, so basically we're gonna call this API, if you haven't worked with APIs before. I would recommend going and doing spreadsheet automation 1 0 1. That course will take you through very basic steps of coding and get you to APIs and explain all about APIs. Very quick, not quickly, but very detailed. Basically, we just need to go to A-A-U-R-L and get the response there, but the URL that we want is gonna be pretty crazy. We're gonna call this full URL. And I'm gonna put it in back Icks, because we're going to fill this with variables. Basically we have first this A-P-I-U-R-L. So we're gonna do dollar sign and curly brackets and put that A-P-I-U-R-L.

That's gonna be the start of our URL. Then we're gonna put a question mark, access key, and this is all, uh, documented on. Screenshot one's API, how to access their API. I'm just doing it for you here. Now we're gonna equals, we're gonna put in our API key, but we can't just do this, just copy and paste API key. We have to do the same thing we did just before, which is put dollar sign , curly brackets around it. This is called interpolation and we're saying, Hey, yes, we're gonna give you this text screen, this text, but we're gonna grab this text from somewhere else. Okay, now we need to say URL equals. And do you get the last do, do you already a step ahead of me?

We're gonna put this encoded, URL in there. So we're taking the API key. We're taking the A-P-I-U-R-L and the encoded URL. We're all putting it together, but we have to have a few more little. Pieces of information, so we're gonna put an ampersand. I'm gonna say format equals jpeg. We're gonna say ampersand. Cash equals true. We're gonna say ampersand, cash underscore TT L. This is just saying how long do you want the cash to be available for? This is like seconds. 2 5 9 2 0 0 0. That's a lot of seconds. That's. 43,000 minutes, 720 hours.

It's about, let's see, 60 divided, divided by 24. That's about 30 days of seconds. And we need one more thing. Response type equals j. S. So we're saying, Hey, when we tell you this URL that we're gonna go to, we have the correct access key. What kind of response do we want back? We want JSON back. JSON is a very easy to read for computers kind of language. So this computer and this. Function is gonna be able to read this JSON and uh, we're gonna tell it how to read it. We're gonna say Turn JSO Capitalize.

And this is saying, this is A-J-J-S-O-N Capitalize is a function inside of App script that allows us to parse js o. What we're gonna say is you URL fetch, app fetch and go grab that full URL and then just. On the other between these two parentheses, get content, text, and then outside we're gonna say Cash, URL. Now what all this is doing is saying, Hey, go fetch that URL that we've just created. Get back whatever. Get back whatever content text you have that tell us what the response is, then parse it. But then only of all of the information you're giving us only

tell us what is the cash URL. There's a whole lot of other information when you get this response. But honestly, all we need, right, right now all we need is this URL. We could deal with response codes and say, okay, if it's 200, give us the cash URL. If it's something else, give us the error . But for this particular video, we just care about the URL and this function Get screenshot is gonna go to that target URL. At the API and give us back some image . Actually it's gonna give us back, sorry. It's gonna give us back, not the image , but the URL to the image . So I'm gonna hit save and I'm gonna go try it. I'm gonna say get screenshot and see what happens. So we have now nothing equals.

Get screenshot. I'm gonna put this URL in here, better sheet.co. And I'm gonna hit enter and see. Do we get an error ? Probably. So we say, okay, this is all saying basically it didn't work. But let's see if we can do something else. Let's see, maybe it is a permissions. Let's hit run. I am gonna hit continue. I do believe maybe it is, that is just this HTPS there that we just need a full URL That is exactly the issue. It was just that we needed the exact full uur L HTPs slash slash and it works. So we can actually go to this URL and see what is at this URL is the image . All we're doing here in B is saying wrapping that URL around image ,

let's. Let's get screenshot for a three. We're gonna get an error . Let's do HTPS. Boom, it works. And let's do the next couple just to make sure it's working for all of these kinds of things. So I'm really interested in this Google search. Oh, it funny enough, this Google search gave it an error . It's, it's doing this thing that Google has done now recently is like. You need to authorize it. You're a human, so that's not working. But the screenshot of a Google sheet is working Pretty cool, right? That basically we can do this. Yes, Google search is not working, but only because it's not really a human doing the screenshot.

Alright, let's save this. So now that we know that this screenshot works, we need the full URL. Let's save it to a drive. So we'll create another function , save screenshot. To drive. And what this is gonna do is we don't necessarily want this like in a sheet like this, like we're just gonna list the RL and then go grab the image . We know the Im URL. We want, let's say this like web flow pricing or better sheet slash pricing, right? Um, we know that URL and we want to go to it every week. So we're gonna say. Cons, cash. URL equals get screenshot. We're gonna put in quotes, H to TPS, better sheets.

Deco slash pricing if you want, but it could be anything. Can have that trailing. Whatever. So we're gonna grab the screenshot here. Now what's interesting is we save this cash for 30 days, so you might want to decrease that amount. If you do, then you'll get a new screenshot. Uh, however, in my particular case, screenshot one only gives you like a hundred. For free. Then it starts charging you. You want to be charged. If you wanna be charged. You know, depends on how, how many screenshots you really need. Do you need 'em every week, every day, every month, every two months, whatever that is,

we're going to create a blob. Why do I say blob? I say blob because that's how files are saved in Google Drive. So we're gonna say URL, fetch app dot fetch. Go grab that cash. URL. And again, we're not getting the URL here of this website. We are getting the response URL of screenshot one, and then we're saying get blob and we want to set the name. This is a very particular, because we want a consistent screenshot.

Name hyphen. And then I'm gonna add dollar sign and do some interpretation here of new date. And I'm gonna just say.to ISO string . This is just saying, Hey, create a new timestamp , but call it A ISO string , and then at the end, jpeg. Okay, so we're just saying put a date and time here. Of whatever this file is. Now the folder, this folder situation is very complicated. Drive sort of makes it weird. We do cons, folders equals drive, app dot, get folders by name and

we're gonna search for better sheets. Screenshots. You can name this anything you want, you just need to know what is the f. Folder name, yes. You can create a folder and then put the name here. However, you don't have to. I'll show you why. We're gonna let folder. That's just a variable that says, here's a random variable, just a blank variable, not random, blank called folder. And if folders has next, yes, folders go up to this. Folders do has next. And if that's true. Meaning there is a folder there. Then we're gonna do folder equals folders do next.

So we're saying, Hey, if you go and get the all the folders by name and there is a next one, that next one, that's the name of the folder and that's the folder we want. However else should put this on a new line. There is an el we have to deal with else, meaning if this folder. Doesn't exist and it's false here. Doesn't have a next one. Let's go make it. We'll say folder equals drive app, create folder, and you're gonna name it the exact same. So basically all of this is saying, Hey.

Go look for the folder called Better Sheets screenshots. If it does exist, give us back that folder. If it doesn't exist, go create it. And now we're gonna return. So this is the end of our So function here. We're gonna turn folder, create file blob. This blob up here. This is the JPEG we're saving. And we're gonna get the URL. Now, where do we want to get this? We can't call this a variable. We can just say variable screenshot. URL equals this. And instead of a return, let's append to somewhere.

Let's create a sheet. Called saved. And we're gonna just append here in the A column, the saved URL. We're gonna get this URL, so we're gonna say spreadsheet app, get active spreadsheet , get sheet by name. Saved append row. And what are we gonna append this screenshot, URL in. And this is, let's bring this up to the top. This is in square brackets. Okay. So every time this runs, it's going to append right here, a new URL, maybe let's say date as well. Let's put a, the new date here.

So how do we do that? Let's go back to our here and we're gonna do a comma new date and it'll have a timestamp . So let's run save. Screenshot to drive. We're gonna select it up here. Save everything or click save project to drive. Let's hit run. We may ha need more authorization . Waiting patiently to see if we have any errors. Let's go. We have a RL, we have a timestamp . Great. And if we go to that URL, it is saved. Let's go to our drive as well, and there's better sheet screenshots. And there it is. So if we run this again right now, obviously this site hasn't changed, but if we run it again,

it's doing all of its work. There's another Google Drive file. Fantastic. Right. So how do we automate this? Let's go back to our app script . We have two functions . Get the screenshot and save the screenshot. Save the screenshot actually uses get screenshot, which is cool, which sometimes you like to put it like this. Sometimes you can do it like that. Save screenshots at the top. But how do we automate? Let's go over to the left side. Go to triggers. Now on the bottom right there's a big blue button called add trigger . Choose which function to run. This is a dropdown menu that shows all of our functions . If you have other functions in your sheet, you're gonna have to find it and, and

we're gonna use save screenshot to drive. Select event Source is gonna be time driven, select type of timer. I want to do it every month on the. First of the month. Great, and I'll do it at five to 6:00 AM Hit save. These are all things you can change yourself. And now we have a app script trigger , an automatic automation that has been created. If we want to delete this and we don't want to save these particular screenshots anymore, click three buttons to the right and delete trigger .

Delete forever. If you want more than one, we need to do a couple things. This is only one site Save. You can call this Save Better sheets. Then we can copy this, save better sheets, paste it underneath it and say Save Webflow pricing. And let's go get that URL over here somewhere and we can change the URL right there. And now we have a whole new function that's saving this. Now let's save. And if we go over two triggers, we can create two triggers, one

that saves better sheets, and one that saves Webflow add trigger . And now we have two functions here. They are both using this get screenshot, which is totally fine and actually really nice functionality here. But if you don't want to be copying all of this stuff, there is one other way we can do this. Save URL to drive and put in URL here. And instead of putting this as a uh, text, we can just put it as a variable URL and we can save this URL and make that the variable there. Now, every time we save this URL, we may want to rename this folder.

Okay, so these are gonna be all the screenshots of everything. Maybe you want a unique folder for each URL. So let's try to do that. We can put, instead of these quotes, can put backtick instead of better sheets, screenshots, let's call it screenshots for, and do interpolation as well here. And literally the URL that it is is going to be in the name of the folder. Let's see if that works. So we need a trigger to trigger this, so we actually need to create another function , save better sheets, put that in quotes and run save.

URL to drive and do HTPS better sheets.com. Now, much simpler function to run. We can call this save web flow pricing. Again, grab this URL. So what's going on here is we are creating a little function . That just says, Hey, go to this URL to save, to drive and use this URL. However, I want to, I wanna share one cool thing we can do here. We can add multiple variables, save this URL, so we can say, here's the URL, here's the folder name,

and here we say better sheets.co. And here with, for Webflow, we say Webflow pricing. And instead of screenshots for save, this URL, we put that folder name there. So this is a really cool way to say, Hey, yes, I wanna save the Webflow, I wanna save this URL, and I wanna call the folder this. So now every time we run this. It's going to save that URL, but use a different name for the folder name. Pretty cool, right? And then all we have to do is automate this function for save better sheets. All we have to do is automate this, save webflow pricing.

We can even test this out just to see if this is work, working, and see if we have a web flow pricing, uh, folder. So it looks like it all worked fine. And here it is, screenshots for Webflow pricing. And there is our screenshot. Fantastic, right? And every time we run this Save Webflow pricing. If we've automated it, it's going to just add. To this drive folder. Pretty cool, right? This is awesome that we can do automatic screenshotting from Google Sheets with screenshot one and do it in a way where we're saving this to a particular Google Drive folder. Again, if you're watching this, not on Better sheets, on Better sheets.co.

All members have access to this exact file. Go grab it. Become a. Member of Better Sheets today. Thanks for those who are already members of Better Sheets. Appreciate you sticking around this whole video. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.