1 00:00:00,000 --> 00:00:01,049 2 00:00:01,049 --> 00:00:02,340 SUNDAR SOLAI: Hello, everybody. 3 00:00:02,340 --> 00:00:03,500 My name is Sundar. 4 00:00:03,500 --> 00:00:05,350 Welcome to the CS50 seminar. 5 00:00:05,350 --> 00:00:07,350 It's great to see so many people here in person. 6 00:00:07,350 --> 00:00:10,460 And hello to everyone tuning in online as well. 7 00:00:10,460 --> 00:00:12,830 So just a little bit about myself before we get started. 8 00:00:12,830 --> 00:00:15,080 So, like I said, my name is Sundar. 9 00:00:15,080 --> 00:00:17,900 I'm a junior here at Harvard, and I live in Currier House. 10 00:00:17,900 --> 00:00:21,020 I study computer science, and I also really love statistics. 11 00:00:21,020 --> 00:00:23,870 I was on CS50 staff last year as a teaching fellow. 12 00:00:23,870 --> 00:00:27,890 And I'm really happy to be back and sharing this technology through Google 13 00:00:27,890 --> 00:00:30,410 with a lot of there really useful APIs. 14 00:00:30,410 --> 00:00:33,680 I spent this past summer interning at Google in California, 15 00:00:33,680 --> 00:00:35,480 where I was on the G Suite team. 16 00:00:35,480 --> 00:00:38,762 And I'll tell you a lot more about the various APIs that we have 17 00:00:38,762 --> 00:00:40,970 and how you can use those in your own final projects, 18 00:00:40,970 --> 00:00:43,530 or whatever else you might be working on. 19 00:00:43,530 --> 00:00:45,800 So let's get started. 20 00:00:45,800 --> 00:00:48,110 OK, so what is G Suite? 21 00:00:48,110 --> 00:00:53,060 It's essentially a platform of all your favorite Google applications, 22 00:00:53,060 --> 00:00:57,650 including but not limited to what you see here, including Gmail, Calendar, 23 00:00:57,650 --> 00:01:01,730 Docs, Sheets, Slides, Forms and all these other really useful tools 24 00:01:01,730 --> 00:01:03,020 for productivity. 25 00:01:03,020 --> 00:01:08,550 And so G Suite has both the consumer applications that you're used to, 26 00:01:08,550 --> 00:01:11,590 but, also, a big part of it is the enterprise solutions. 27 00:01:11,590 --> 00:01:16,590 So, for instance, at college we have @college.harvard.edu email addresses, 28 00:01:16,590 --> 00:01:17,930 which are done through G Suite. 29 00:01:17,930 --> 00:01:21,860 And so all the services that we use have Google products that tie into them. 30 00:01:21,860 --> 00:01:24,500 So, for instance, I could look at my college calendar 31 00:01:24,500 --> 00:01:27,650 through Google Calendar. 32 00:01:27,650 --> 00:01:31,042 And, today, the focus is going to be on the various APIs 33 00:01:31,042 --> 00:01:33,500 that you can use to programmatically interact with G Suite. 34 00:01:33,500 --> 00:01:37,190 So in addition to being probably a user of these products, 35 00:01:37,190 --> 00:01:41,510 you can be a developer and incorporate programmatic interactions 36 00:01:41,510 --> 00:01:44,810 with these platforms, so that users of your own applications 37 00:01:44,810 --> 00:01:48,470 might be able to generate spreadsheets on the fly. 38 00:01:48,470 --> 00:01:52,700 Or, once a Google form gets submitted, perhaps a certain action 39 00:01:52,700 --> 00:01:54,760 takes place every time someone submits a form. 40 00:01:54,760 --> 00:01:56,530 And so we'll talk about different examples like that. 41 00:01:56,530 --> 00:01:59,030 And then you can brainstorm on your own to see how that 42 00:01:59,030 --> 00:02:02,360 might work into your own workflows. 43 00:02:02,360 --> 00:02:05,240 So I'm going to spend the first part of this talk describing 44 00:02:05,240 --> 00:02:08,750 how you might interact with the APIs in the traditional way. 45 00:02:08,750 --> 00:02:12,740 And then we'll talk about Google Apps Script, which is this really amazing-- 46 00:02:12,740 --> 00:02:15,560 and I'm surprised by how many people still haven't heard of it 47 00:02:15,560 --> 00:02:20,060 because it's fabulous in how quickly you can interact with the Google APIs 48 00:02:20,060 --> 00:02:22,854 without really having to do any overhead in getting started. 49 00:02:22,854 --> 00:02:24,770 So we'll talk about the traditional way first. 50 00:02:24,770 --> 00:02:27,200 And then we'll get into that too. 51 00:02:27,200 --> 00:02:32,822 So say I want to create a project, and I want to use the YouTube API. 52 00:02:32,822 --> 00:02:33,780 So how would I do that? 53 00:02:33,780 --> 00:02:38,300 So the first step is to navigate to console.developers.google.com. 54 00:02:38,300 --> 00:02:42,200 And this is the Developer Console where you can create a project. 55 00:02:42,200 --> 00:02:44,780 So you see here there's that Select a Project dropdown. 56 00:02:44,780 --> 00:02:48,180 And you can either use an existing project or create a new one. 57 00:02:48,180 --> 00:02:50,960 So you navigate there and do whatever is appropriate. 58 00:02:50,960 --> 00:02:53,245 And then you can enable whichever APIs you think 59 00:02:53,245 --> 00:02:54,870 you might be using in your application. 60 00:02:54,870 --> 00:02:57,959 And so you'll see here there are really a ton of APIs available. 61 00:02:57,959 --> 00:03:00,500 I think since I created this slide the interface has actually 62 00:03:00,500 --> 00:03:01,670 changed a tiny bit. 63 00:03:01,670 --> 00:03:05,420 But the point remains that there are a lot of APIs from Android, to YouTube, 64 00:03:05,420 --> 00:03:08,480 to G Suite that you can just flip on and then 65 00:03:08,480 --> 00:03:12,180 you can get the credentials to actually use those APIs in your application. 66 00:03:12,180 --> 00:03:14,690 So this is in the Library tab that you see here. 67 00:03:14,690 --> 00:03:18,700 But once you enable the APIs, then you can get the credentials 68 00:03:18,700 --> 00:03:19,970 at the next step. 69 00:03:19,970 --> 00:03:24,410 And so once you get the credentials, you can download what's called an API key. 70 00:03:24,410 --> 00:03:27,140 And then use that to prove to Google, hey, it's me. 71 00:03:27,140 --> 00:03:30,350 I'm going to be using the Google Drive API. 72 00:03:30,350 --> 00:03:33,650 Let me read files from the Drive. 73 00:03:33,650 --> 00:03:34,910 So you do that. 74 00:03:34,910 --> 00:03:38,150 And now I'm going to show some Python examples of how you might actually 75 00:03:38,150 --> 00:03:42,110 do this off process to prove to Google you are indeed who you say you are, 76 00:03:42,110 --> 00:03:44,540 and therefore, you should have access to the API. 77 00:03:44,540 --> 00:03:49,430 So there's two different kinds of off that you could be doing, either simple 78 00:03:49,430 --> 00:03:50,660 or authorized. 79 00:03:50,660 --> 00:03:54,230 And so I'll point out the distinction here and then we'll dig in a little bit 80 00:03:54,230 --> 00:03:58,260 to what this code actually does and what the differences are. 81 00:03:58,260 --> 00:04:03,740 So, in one case, the simpler case, you have simple API access. 82 00:04:03,740 --> 00:04:07,460 And this is for things such as the YouTube Data API 83 00:04:07,460 --> 00:04:10,280 where the point of you interacting with the API 84 00:04:10,280 --> 00:04:13,730 is not to do anything that's really user specific, so more just general. 85 00:04:13,730 --> 00:04:17,320 I want to search YouTube and show the top 10 cat videos 86 00:04:17,320 --> 00:04:18,519 or something like that. 87 00:04:18,519 --> 00:04:22,100 And on the other hand, you might need more sophisticated authorization 88 00:04:22,100 --> 00:04:25,340 because you might be parsing a user's Gmail messages 89 00:04:25,340 --> 00:04:27,500 and then creating calendar events based on that. 90 00:04:27,500 --> 00:04:30,500 And so that requires a higher level access 91 00:04:30,500 --> 00:04:32,947 to what the user actually wants to be doing. 92 00:04:32,947 --> 00:04:35,780 And so for that reason, you're going to need to do a little bit more 93 00:04:35,780 --> 00:04:37,310 in the boiler plate. 94 00:04:37,310 --> 00:04:39,290 So let's actually take a look at this. 95 00:04:39,290 --> 00:04:41,727 So these examples are in Python, but that doesn't 96 00:04:41,727 --> 00:04:43,310 mean that you're restricted to Python. 97 00:04:43,310 --> 00:04:46,280 In fact, you can basically use any programming language you want. 98 00:04:46,280 --> 00:04:49,940 And the Google API client library should be available for that. 99 00:04:49,940 --> 00:04:55,100 And you can always use with HTTP, get and post requests as well. 100 00:04:55,100 --> 00:04:58,150 So looking at the simple API access boilerplate, 101 00:04:58,150 --> 00:04:59,680 it's really only three lines. 102 00:04:59,680 --> 00:05:03,290 So first we import the API client. 103 00:05:03,290 --> 00:05:06,250 So that's what you can install through Google. 104 00:05:06,250 --> 00:05:09,010 So in Python, you just say something like pip install 105 00:05:09,010 --> 00:05:11,990 and then Google API client libraries or something like that. 106 00:05:11,990 --> 00:05:16,630 And this is all available on the website on developers.google.com. 107 00:05:16,630 --> 00:05:19,330 So once you have that installed, you'd import it. 108 00:05:19,330 --> 00:05:22,120 And then back to those credentials that I 109 00:05:22,120 --> 00:05:24,040 was showing earlier in the developer console, 110 00:05:24,040 --> 00:05:25,480 you can get an API key from there. 111 00:05:25,480 --> 00:05:28,540 And so this is some very long string that is unique to you 112 00:05:28,540 --> 00:05:33,940 and shows Google that you are whichever user is trying to use a particular API. 113 00:05:33,940 --> 00:05:35,475 So you'd paste in that key here. 114 00:05:35,475 --> 00:05:37,600 And something that I'll point out is that if you're 115 00:05:37,600 --> 00:05:42,194 writing an actual application that you intend to be used by many people, 116 00:05:42,194 --> 00:05:44,860 for security purposes, you probably don't want your API key just 117 00:05:44,860 --> 00:05:46,510 sitting around in the source code. 118 00:05:46,510 --> 00:05:49,120 That's something that's best kept in a more secure place 119 00:05:49,120 --> 00:05:50,740 that you then pull in over here. 120 00:05:50,740 --> 00:05:53,770 But it shouldn't just be plainly visible to everybody. 121 00:05:53,770 --> 00:05:55,870 But you put that in nonetheless. 122 00:05:55,870 --> 00:06:00,160 And then finally, you do this in line eight-- the SERVICE= discovery.build, 123 00:06:00,160 --> 00:06:03,200 and then you specify what kind of API you want to be using. 124 00:06:03,200 --> 00:06:07,540 And so the idea here is that as a string that first parameter you're stating, 125 00:06:07,540 --> 00:06:09,130 I want to use the YouTube API. 126 00:06:09,130 --> 00:06:10,660 And then specify what version. 127 00:06:10,660 --> 00:06:13,180 And then it's pulling in the key that you said earlier 128 00:06:13,180 --> 00:06:14,360 as that third argument. 129 00:06:14,360 --> 00:06:16,240 And then together what you're getting back 130 00:06:16,240 --> 00:06:21,850 is this actual API client that you can then do various function calls from, 131 00:06:21,850 --> 00:06:25,260 such as searching YouTube for your favorite cat videos. 132 00:06:25,260 --> 00:06:27,540 OK, so let's keep going. 133 00:06:27,540 --> 00:06:30,470 On the other hand, like I mentioned, we have authorized API access. 134 00:06:30,470 --> 00:06:33,178 And so it's a little bit more sophisticated what's going on here. 135 00:06:33,178 --> 00:06:36,000 I'm not going to delve into it too deep, but just the points 136 00:06:36,000 --> 00:06:38,500 that you would need to get started on your own applications. 137 00:06:38,500 --> 00:06:40,860 Because what I hate the most is we go through CS50, 138 00:06:40,860 --> 00:06:43,680 and we all become these rock star programmers. 139 00:06:43,680 --> 00:06:47,122 But we get limited by the actual boilerplate 140 00:06:47,122 --> 00:06:48,330 that's needed to get started. 141 00:06:48,330 --> 00:06:50,130 So try using this. 142 00:06:50,130 --> 00:06:52,890 And to give you some general sense of what's going on, 143 00:06:52,890 --> 00:06:55,000 we're doing our imports at the top. 144 00:06:55,000 --> 00:06:56,370 But then line 5 is key. 145 00:06:56,370 --> 00:06:58,500 So this line that says SCOPES-- 146 00:06:58,500 --> 00:07:01,980 what we're doing there is we're specifying what parts of the APIs 147 00:07:01,980 --> 00:07:03,100 we want to be using. 148 00:07:03,100 --> 00:07:05,880 And so in addition to saying I want to use the Drive API, 149 00:07:05,880 --> 00:07:09,360 you might provide one or more specific scopes within that API. 150 00:07:09,360 --> 00:07:12,000 So for instance, you might be writing an application that 151 00:07:12,000 --> 00:07:16,200 needs only to read files from Drive and doesn't request any rights 152 00:07:16,200 --> 00:07:17,410 from the user. 153 00:07:17,410 --> 00:07:21,300 And so if that's the case, then you'd want to use the drive.readonly scope. 154 00:07:21,300 --> 00:07:25,860 And there are similar scopes in Gmail, and Slides, and other G Suite 155 00:07:25,860 --> 00:07:28,480 and Google API products. 156 00:07:28,480 --> 00:07:31,860 And so the advantage of using the tightest scope possible 157 00:07:31,860 --> 00:07:35,070 is that when the dialog appears for the user to verify, 158 00:07:35,070 --> 00:07:38,940 yes, I'd like this application to have access to my drive files, 159 00:07:38,940 --> 00:07:41,557 it's more secure for the user because they don't 160 00:07:41,557 --> 00:07:43,140 have to give full access to the files. 161 00:07:43,140 --> 00:07:45,306 They only need to give read access, or write access, 162 00:07:45,306 --> 00:07:47,610 or whatever you actually need for the application. 163 00:07:47,610 --> 00:07:49,500 So that's just a good practice. 164 00:07:49,500 --> 00:07:52,320 And so after you establish for scopes, you 165 00:07:52,320 --> 00:07:54,774 go through this off flow in lines 9 to 13. 166 00:07:54,774 --> 00:07:57,190 But then once you get through that, at the end of the day, 167 00:07:57,190 --> 00:07:59,880 you're still building the service like you did before. 168 00:07:59,880 --> 00:08:03,700 And so after this top section, then you can get your actual application, 169 00:08:03,700 --> 00:08:06,640 which is the fun part. 170 00:08:06,640 --> 00:08:09,290 I'll just point out that you can use multiple scopes. 171 00:08:09,290 --> 00:08:11,170 So you're not limited to a single scope. 172 00:08:11,170 --> 00:08:15,430 And you can say I want to use Drive, I want to use Sheets, 173 00:08:15,430 --> 00:08:17,640 I want to use Slides and create a huge integration. 174 00:08:17,640 --> 00:08:18,890 So that's really exciting too. 175 00:08:18,890 --> 00:08:21,672 176 00:08:21,672 --> 00:08:24,630 And now let's talk about some examples of what you can do with the API. 177 00:08:24,630 --> 00:08:28,260 And if the live demo gods are on my side, 178 00:08:28,260 --> 00:08:33,382 we'll actually see some examples of these scripts in action. 179 00:08:33,382 --> 00:08:35,340 So the first one that we're going to talk about 180 00:08:35,340 --> 00:08:38,220 is this searching YouTube for videos. 181 00:08:38,220 --> 00:08:40,860 And so what's going on here-- 182 00:08:40,860 --> 00:08:44,670 this is a simple API access because all we're doing is searching. 183 00:08:44,670 --> 00:08:47,940 We're not requiring anything about the user's identity. 184 00:08:47,940 --> 00:08:51,480 And so we just use the API key as before. 185 00:08:51,480 --> 00:08:57,240 And then what we do is we have this section from lines 5 to 8 186 00:08:57,240 --> 00:09:02,970 that's basically helping us print out what videos we uncover. 187 00:09:02,970 --> 00:09:04,980 But the key part here and what I really want 188 00:09:04,980 --> 00:09:07,229 you to focus on with actually interacting with the API 189 00:09:07,229 --> 00:09:11,530 is that in line 10 after we get access to the YouTube API, 190 00:09:11,530 --> 00:09:14,340 in line 11, that's where we're doing the actual search. 191 00:09:14,340 --> 00:09:17,160 And so you'll see that we're going YOUTUBE.search. 192 00:09:17,160 --> 00:09:20,165 And then within dot search, we have this method called list. 193 00:09:20,165 --> 00:09:23,290 And so with list, you can specify what exactly you're trying to search for. 194 00:09:23,290 --> 00:09:25,500 And so we do that here with the query. 195 00:09:25,500 --> 00:09:29,500 And so if you look at what capital query has actually been established 196 00:09:29,500 --> 00:09:31,719 as in line 5, we see that it's Python. 197 00:09:31,719 --> 00:09:33,510 And so what this is doing is it's searching 198 00:09:33,510 --> 00:09:36,720 YouTube for videos related to Python. 199 00:09:36,720 --> 00:09:40,620 And then in lines 14 to 17 this is all just normal Python. 200 00:09:40,620 --> 00:09:42,810 It has nothing to do with the API themselves. 201 00:09:42,810 --> 00:09:44,940 We're just iterating through what we get back 202 00:09:44,940 --> 00:09:47,921 that was stored as the result or R-E-S, Res. 203 00:09:47,921 --> 00:09:49,170 And then we iterate over that. 204 00:09:49,170 --> 00:09:53,190 And we just print out every YouTube video that we uncover. 205 00:09:53,190 --> 00:09:56,160 So let's take a look at this in action. 206 00:09:56,160 --> 00:10:00,080 So I will close out of the slides for a second. 207 00:10:00,080 --> 00:10:01,340 OK. 208 00:10:01,340 --> 00:10:06,287 So I have this example script pulled up here just to show you. 209 00:10:06,287 --> 00:10:07,370 It's the same exact thing. 210 00:10:07,370 --> 00:10:08,980 I made one slight change. 211 00:10:08,980 --> 00:10:14,330 And that was instead of having query be Python, I have it as sys.rv1. 212 00:10:14,330 --> 00:10:18,620 And so this just looks at the command line arguments when I call the script 213 00:10:18,620 --> 00:10:22,190 and looks at the first one that we supply. 214 00:10:22,190 --> 00:10:25,184 And so you'll notice here that these scripts are very easy to modify. 215 00:10:25,184 --> 00:10:28,100 And if you know Python, you can do really whatever you want with them. 216 00:10:28,100 --> 00:10:31,310 So use the API as an access point to these Google technologies, 217 00:10:31,310 --> 00:10:35,650 but then bring in your own creativity to do whatever you really want to do. 218 00:10:35,650 --> 00:10:39,080 The sky's the limit when it comes to programming. 219 00:10:39,080 --> 00:10:40,490 So let's actually run this. 220 00:10:40,490 --> 00:10:43,280 So the way I run it is Python, and the name of the script, 221 00:10:43,280 --> 00:10:45,140 and then whatever I want to search for. 222 00:10:45,140 --> 00:10:50,900 So for instance, I might want to search for videos on CS50. 223 00:10:50,900 --> 00:10:53,520 So I do that, and let's see what we get back. 224 00:10:53,520 --> 00:10:58,550 225 00:10:58,550 --> 00:11:00,240 I'm having some issues with my Python 3. 226 00:11:00,240 --> 00:11:02,030 So I'm going to use Python 2. 227 00:11:02,030 --> 00:11:04,430 But this script should work for either one. 228 00:11:04,430 --> 00:11:07,115 I just had a package installation error. 229 00:11:07,115 --> 00:11:08,540 So let's do this with Python 2. 230 00:11:08,540 --> 00:11:09,350 It's searching. 231 00:11:09,350 --> 00:11:10,470 And then there we go. 232 00:11:10,470 --> 00:11:13,830 We get back top five videos on CS50. 233 00:11:13,830 --> 00:11:14,330 Cool. 234 00:11:14,330 --> 00:11:19,210 So let's go back to our examples here. 235 00:11:19,210 --> 00:11:21,910 So that was an example of simple API access. 236 00:11:21,910 --> 00:11:25,420 And now let's touch on a more sophisticated example, 237 00:11:25,420 --> 00:11:29,560 where you actually need to get the user to go into their Google Drive account 238 00:11:29,560 --> 00:11:33,770 or rather have the API go into a user's Google Drive account. 239 00:11:33,770 --> 00:11:37,180 And so the boilerplate is very similar to what I showed earlier. 240 00:11:37,180 --> 00:11:41,770 And you'll see here that we're using the read-only scope from Google Drive. 241 00:11:41,770 --> 00:11:45,100 And then the action happens in line 14. 242 00:11:45,100 --> 00:11:47,050 So in line 14, we get back-- 243 00:11:47,050 --> 00:11:48,580 we build the service. 244 00:11:48,580 --> 00:11:52,250 And then in line 15 we're actually listing the files that we want. 245 00:11:52,250 --> 00:11:56,560 And so what this is doing is that it lists all the files that someone has. 246 00:11:56,560 --> 00:12:00,000 And then it iterates in line 16 and 17 over those files that come back 247 00:12:00,000 --> 00:12:02,145 and just prints out their name. 248 00:12:02,145 --> 00:12:04,820 All right. 249 00:12:04,820 --> 00:12:07,270 You can also do things with the Sheets and Slides. 250 00:12:07,270 --> 00:12:08,370 So the Slides API-- 251 00:12:08,370 --> 00:12:10,922 I think it came out maybe a year or a year and a half ago. 252 00:12:10,922 --> 00:12:13,880 Really exciting, and you can think of a lot of neat use cases for this. 253 00:12:13,880 --> 00:12:17,770 So for instance, suppose I were to give a lot of talks like this, 254 00:12:17,770 --> 00:12:20,090 but because I do them in different locations, 255 00:12:20,090 --> 00:12:22,690 the title slide needs to reflect where I'm giving the talk. 256 00:12:22,690 --> 00:12:26,530 Or, perhaps, I could just create a script that would take a template deck 257 00:12:26,530 --> 00:12:30,260 and then edit the title slide so that it fits whatever 258 00:12:30,260 --> 00:12:32,150 talk I'm going to be giving that day. 259 00:12:32,150 --> 00:12:34,450 So you can imagine these customized presentations. 260 00:12:34,450 --> 00:12:38,650 You might be a executive or reporting to an executive at a business. 261 00:12:38,650 --> 00:12:42,759 And you'd want to give a slide deck every quarter 262 00:12:42,759 --> 00:12:44,300 with the performance for the company. 263 00:12:44,300 --> 00:12:47,410 And so you can create charts maybe in Google Sheets, 264 00:12:47,410 --> 00:12:50,350 and then have those sent right into Slides 265 00:12:50,350 --> 00:12:53,080 every quarter for your presentation to the boss. 266 00:12:53,080 --> 00:12:55,350 And we have a really cool example on GitHub 267 00:12:55,350 --> 00:13:00,760 that is a converter from markdown to Google Slides, so check that out too. 268 00:13:00,760 --> 00:13:05,550 So the example that I'll show now is the ability to create a template deck, 269 00:13:05,550 --> 00:13:08,170 put in some placeholder text or shapes, and then replace 270 00:13:08,170 --> 00:13:12,480 those placeholders with images or text that you really want to use. 271 00:13:12,480 --> 00:13:15,580 And so this is useful again for that use case 272 00:13:15,580 --> 00:13:18,550 where you might be creating the same or similar presentation 273 00:13:18,550 --> 00:13:20,590 for a lot of different spaces, and so being 274 00:13:20,590 --> 00:13:23,910 able to start with one common template and then going from there. 275 00:13:23,910 --> 00:13:27,130 And so we'll see in this example with the Slides API, 276 00:13:27,130 --> 00:13:30,347 and it's very similar in the Sheets API, among a few others 277 00:13:30,347 --> 00:13:32,680 that the requests that you create-- so what you actually 278 00:13:32,680 --> 00:13:34,721 want to be doing to interact with your slide deck 279 00:13:34,721 --> 00:13:38,440 or to interactive spreadsheet goes in this JSON like structure. 280 00:13:38,440 --> 00:13:41,050 And so in Python, it's a dictionary. 281 00:13:41,050 --> 00:13:45,040 So we have an array or a list, I should say, of requests. 282 00:13:45,040 --> 00:13:48,130 And each one is this JSON-esque blob. 283 00:13:48,130 --> 00:13:51,610 And so you'll see here that we have these two specific requests happening. 284 00:13:51,610 --> 00:13:55,580 Replace all text, and replace all shapes with image. 285 00:13:55,580 --> 00:13:59,440 And so the first part here is finding the title, 286 00:13:59,440 --> 00:14:01,210 and then replacing that with hello world. 287 00:14:01,210 --> 00:14:06,700 And then the second part is looking for something that says logo 288 00:14:06,700 --> 00:14:10,070 and sticking in a particular image that we want to include. 289 00:14:10,070 --> 00:14:12,520 And then while we create those requests, they 290 00:14:12,520 --> 00:14:16,450 don't actually get executed until you use the batch update command. 291 00:14:16,450 --> 00:14:20,500 And so that's key here is that we create all requests at once. 292 00:14:20,500 --> 00:14:23,224 And then we send them over using batch update. 293 00:14:23,224 --> 00:14:25,390 And this is really useful because rather than having 294 00:14:25,390 --> 00:14:29,620 to ping the API hundreds of times, you can bundle all your requests together 295 00:14:29,620 --> 00:14:30,880 and then do it in one shot. 296 00:14:30,880 --> 00:14:35,620 And so this is helpful to help avoiding hitting the API limit that 297 00:14:35,620 --> 00:14:39,074 is imposed on these APIs to make sure that you're using them reasonably. 298 00:14:39,074 --> 00:14:40,240 So let's try this in action. 299 00:14:40,240 --> 00:14:42,500 I have a modified version of the script. 300 00:14:42,500 --> 00:14:44,870 So head over to my terminal. 301 00:14:44,870 --> 00:14:47,120 I think I called it slides.py. 302 00:14:47,120 --> 00:14:50,310 So I'll show you the entire script before we run it. 303 00:14:50,310 --> 00:14:54,620 So there's a lot more code here, but much of it is just that same off flow 304 00:14:54,620 --> 00:14:55,820 that you've seen earlier. 305 00:14:55,820 --> 00:14:57,380 So we have that in the beginning. 306 00:14:57,380 --> 00:14:59,255 And then I'll just point out here we're going 307 00:14:59,255 --> 00:15:04,160 to be using an image file that I have stored on Google Drive called logo.png. 308 00:15:04,160 --> 00:15:07,850 And then I'm going to be using a template file called Slides Example. 309 00:15:07,850 --> 00:15:13,220 So the script is going to duplicate my Slides Example a slide show. 310 00:15:13,220 --> 00:15:16,580 And then I'm going to modify that new slide show in order 311 00:15:16,580 --> 00:15:20,847 to have the logo picture, as well as the text that I want to include. 312 00:15:20,847 --> 00:15:23,430 And so because I'm going to be copying a file in Google Drive, 313 00:15:23,430 --> 00:15:25,760 I'm going to actually need the drive scope here. 314 00:15:25,760 --> 00:15:26,940 So I have that listed first. 315 00:15:26,940 --> 00:15:29,150 And then I also have the presentation scope 316 00:15:29,150 --> 00:15:34,130 so that I can do the modifications on the slide deck once I've copied it. 317 00:15:34,130 --> 00:15:37,730 So I go through, and I use my discovery.build 318 00:15:37,730 --> 00:15:40,430 to get my drive and my slides access. 319 00:15:40,430 --> 00:15:45,290 And then what we have down here is we're looking through Drive. 320 00:15:45,290 --> 00:15:49,455 So we're listing all files that have the name of the template file. 321 00:15:49,455 --> 00:15:51,830 And the template file I think I called it Slides Example. 322 00:15:51,830 --> 00:15:54,950 So we go through Drive, and we find anything that's called Slides Example. 323 00:15:54,950 --> 00:15:56,783 And then you see here at the end of the line 324 00:15:56,783 --> 00:16:00,520 we have this bracket zero that gets us the first element in the list. 325 00:16:00,520 --> 00:16:02,210 So Python is zero indexed. 326 00:16:02,210 --> 00:16:06,020 And so that will get us the first document or first file 327 00:16:06,020 --> 00:16:08,910 that is named slide's example. 328 00:16:08,910 --> 00:16:09,780 So we do that. 329 00:16:09,780 --> 00:16:11,696 And then what we're going to do is we're going 330 00:16:11,696 --> 00:16:15,920 to use the Drive API again in line 25 to copy that original file 331 00:16:15,920 --> 00:16:18,920 and create a new one called Google Slides API Template 332 00:16:18,920 --> 00:16:21,080 Demo, which we specified over here. 333 00:16:21,080 --> 00:16:22,250 So we copy that, right? 334 00:16:22,250 --> 00:16:26,550 But now all we have is a duplicate of that original slide deck. 335 00:16:26,550 --> 00:16:29,090 So what we want to do is we want to edit that and replace 336 00:16:29,090 --> 00:16:33,320 the contents of that slide deck with the customized information 337 00:16:33,320 --> 00:16:35,240 that we specified up top. 338 00:16:35,240 --> 00:16:39,290 So we have to find first of all where the rectangle placeholder is 339 00:16:39,290 --> 00:16:43,880 that we're going to be replacing in order to include the new image, that 340 00:16:43,880 --> 00:16:45,170 logo.png. 341 00:16:45,170 --> 00:16:49,807 So here we use the Slides API, and then we find the first slide. 342 00:16:49,807 --> 00:16:51,140 So we're getting all the slides. 343 00:16:51,140 --> 00:16:54,230 And then we find the first one using bracket zero. 344 00:16:54,230 --> 00:16:56,699 And then we iterate over all the elements on the slide 345 00:16:56,699 --> 00:16:58,990 until we find something that is of the shape rectangle. 346 00:16:58,990 --> 00:17:01,760 So that's what's going on there. 347 00:17:01,760 --> 00:17:04,369 Then what we do is we go back to the Drive API, 348 00:17:04,369 --> 00:17:10,040 and we find whatever image is called logo.png because that's what 349 00:17:10,040 --> 00:17:11,778 I specified that I want to be using. 350 00:17:11,778 --> 00:17:14,569 And then finally, once we have identified all those key components, 351 00:17:14,569 --> 00:17:16,152 we actually need to put them together. 352 00:17:16,152 --> 00:17:19,560 And so here you'll see those requests that I was talking about earlier. 353 00:17:19,560 --> 00:17:24,650 And so the idea is that we are doing both the replacement of the placeholder 354 00:17:24,650 --> 00:17:26,242 text with the text hello world. 355 00:17:26,242 --> 00:17:27,950 And that we're also going to be replacing 356 00:17:27,950 --> 00:17:33,410 the rectangle with the image, the logo picture, that I've been talking about. 357 00:17:33,410 --> 00:17:36,680 And that image is just going to fit into the exact same space 358 00:17:36,680 --> 00:17:38,720 that the rectangle was in originally. 359 00:17:38,720 --> 00:17:41,900 And then, finally, we use our batch update to actually make that happen. 360 00:17:41,900 --> 00:17:44,060 And then we print out done because we're all done. 361 00:17:44,060 --> 00:17:46,440 OK, so let's try this out. 362 00:17:46,440 --> 00:17:50,030 So I'll just show you the template slide deck first. 363 00:17:50,030 --> 00:17:52,130 So that we have here it's called Slides Example. 364 00:17:52,130 --> 00:17:54,380 All right, and now I'm going to go back to my terminal 365 00:17:54,380 --> 00:17:56,420 and actually run the script. 366 00:17:56,420 --> 00:18:01,370 So this one is Python, slides.py. 367 00:18:01,370 --> 00:18:04,270 And let's see if that works. 368 00:18:04,270 --> 00:18:05,850 So it's copying. 369 00:18:05,850 --> 00:18:07,100 It's finding everything. 370 00:18:07,100 --> 00:18:08,100 And then it's replacing. 371 00:18:08,100 --> 00:18:09,360 And now it's done. 372 00:18:09,360 --> 00:18:11,300 so I'm going to navigate back to My Drive. 373 00:18:11,300 --> 00:18:12,320 And there we go. 374 00:18:12,320 --> 00:18:16,490 We have a new deck that has just been created at 9:55 AM. 375 00:18:16,490 --> 00:18:18,804 So I'm going to open that up. 376 00:18:18,804 --> 00:18:19,470 And there we go. 377 00:18:19,470 --> 00:18:21,439 So the CS50 logo-- 378 00:18:21,439 --> 00:18:22,480 that's floating up there. 379 00:18:22,480 --> 00:18:27,900 And then we also have hello world that has replaced the text 380 00:18:27,900 --> 00:18:29,640 that we had on the original slide deck. 381 00:18:29,640 --> 00:18:30,600 Pretty cool, right? 382 00:18:30,600 --> 00:18:33,510 So this is a very simple toy example, but I 383 00:18:33,510 --> 00:18:35,700 challenge you to explore a lot further with that 384 00:18:35,700 --> 00:18:38,241 and turn it into something that's really useful for a problem 385 00:18:38,241 --> 00:18:39,540 that you have in your own life. 386 00:18:39,540 --> 00:18:41,490 And like I said earlier, it's very feasible 387 00:18:41,490 --> 00:18:44,400 to integrate multiple APIs together and create 388 00:18:44,400 --> 00:18:48,720 a tool that might go into Sheets, get data, turn that into charts, 389 00:18:48,720 --> 00:18:50,040 and then put that into a deck. 390 00:18:50,040 --> 00:18:52,800 391 00:18:52,800 --> 00:18:53,750 Back to this. 392 00:18:53,750 --> 00:18:57,540 393 00:18:57,540 --> 00:19:00,480 So I've been talking about the Google Sheets API as well. 394 00:19:00,480 --> 00:19:02,130 This is a really powerful API. 395 00:19:02,130 --> 00:19:05,340 And I'll show you a project that I did with it in the second. 396 00:19:05,340 --> 00:19:08,160 But I've been mentioning you can do customized reporting. 397 00:19:08,160 --> 00:19:10,950 You can also have data come out of Sheets. 398 00:19:10,950 --> 00:19:14,767 So perhaps you have people logging things into a Google Form. 399 00:19:14,767 --> 00:19:18,100 And then you want to take that data from Sheets and then move it somewhere else. 400 00:19:18,100 --> 00:19:22,250 And so you can do that programmatically with the Sheets API. 401 00:19:22,250 --> 00:19:26,000 And to give you an example of something that I worked on personally with this, 402 00:19:26,000 --> 00:19:28,580 I used a really neat tool called Google Big Query, which 403 00:19:28,580 --> 00:19:30,979 also has a very useful API. 404 00:19:30,979 --> 00:19:34,020 And what's cool about that is that you have access to these enormous data 405 00:19:34,020 --> 00:19:37,220 sets gigabytes or larger in size. 406 00:19:37,220 --> 00:19:40,280 And you can query them in seconds or even fractions 407 00:19:40,280 --> 00:19:42,710 of a second using familiar SQL command. 408 00:19:42,710 --> 00:19:45,710 So I think by this time in CS50 you should 409 00:19:45,710 --> 00:19:49,910 be learning about SQL, which is this really friendly language for pulling 410 00:19:49,910 --> 00:19:52,610 out information from databases. 411 00:19:52,610 --> 00:19:55,280 And so here what I did was I used Google Big Query. 412 00:19:55,280 --> 00:19:57,920 It comes with these really neat example data sets, 413 00:19:57,920 --> 00:20:02,180 so I took the pitch by pitch data for every pitch 414 00:20:02,180 --> 00:20:07,460 thrown in the 2016 MLB season, which is pretty topical at the moment in fact. 415 00:20:07,460 --> 00:20:09,800 And so I took all that data and I aggregated it 416 00:20:09,800 --> 00:20:12,540 into dashboards for every team in the MLB 417 00:20:12,540 --> 00:20:14,930 so that we can compare how different pitchers are doing 418 00:20:14,930 --> 00:20:16,549 and how different hitters are doing. 419 00:20:16,549 --> 00:20:19,340 And then I applied conditional formatting to every different column 420 00:20:19,340 --> 00:20:23,040 and created this heat map where you can see who is excelling and who's not. 421 00:20:23,040 --> 00:20:25,160 And then there are other aspects to this project 422 00:20:25,160 --> 00:20:28,707 such as a chart that shows who's throwing the most fastballs 423 00:20:28,707 --> 00:20:30,290 or who's throwing the most screwballs. 424 00:20:30,290 --> 00:20:34,520 And so it's a great way to visualize data through a spreadsheet. 425 00:20:34,520 --> 00:20:37,010 All right, so enough on that. 426 00:20:37,010 --> 00:20:40,220 I'm going to shift gears now to describing Google Apps Script. 427 00:20:40,220 --> 00:20:44,240 Apps Script is this really neat, powerful platform 428 00:20:44,240 --> 00:20:46,782 by which you can interact with the Google APIs 429 00:20:46,782 --> 00:20:49,490 without having to go through any of the headache that comes along 430 00:20:49,490 --> 00:20:51,330 with the off process. 431 00:20:51,330 --> 00:20:55,100 And it just feels like a much more native approach 432 00:20:55,100 --> 00:20:56,730 to dealing with Google products. 433 00:20:56,730 --> 00:20:58,560 So it's really easy to get started. 434 00:20:58,560 --> 00:21:03,120 And we'll do some neat examples today as well. 435 00:21:03,120 --> 00:21:05,070 So what exactly is Apps Script? 436 00:21:05,070 --> 00:21:06,870 Well, it's symbolized by this icon. 437 00:21:06,870 --> 00:21:10,650 And it's just a new flavor of JavaScript, if you will. 438 00:21:10,650 --> 00:21:14,009 It takes away the API flavor. 439 00:21:14,009 --> 00:21:16,050 So whatever we've been seeing earlier with Python 440 00:21:16,050 --> 00:21:18,360 or whatever other language you might be using, 441 00:21:18,360 --> 00:21:21,660 you don't actually have to use the Google API as an API. 442 00:21:21,660 --> 00:21:25,140 It's as if it's built in to the environment. 443 00:21:25,140 --> 00:21:28,170 And what makes that really nice is that you 444 00:21:28,170 --> 00:21:30,532 don't have to worry about setting up anything with Auth. 445 00:21:30,532 --> 00:21:32,115 Things just work right out of the box. 446 00:21:32,115 --> 00:21:32,970 It's super friendly. 447 00:21:32,970 --> 00:21:34,290 You don't have to install any packages. 448 00:21:34,290 --> 00:21:35,206 Everything just works. 449 00:21:35,206 --> 00:21:37,380 And it's all done on the web. 450 00:21:37,380 --> 00:21:40,350 And there's an IDE found at the script.google.com where 451 00:21:40,350 --> 00:21:43,430 you can get coding right now. 452 00:21:43,430 --> 00:21:47,030 And the thing I really want to emphasize is that it's literally just JavaScript. 453 00:21:47,030 --> 00:21:50,450 And so in CS50 you will be, if you haven't already, 454 00:21:50,450 --> 00:21:51,470 working with JavaScript. 455 00:21:51,470 --> 00:21:53,390 And so you can apply all those ideas that you 456 00:21:53,390 --> 00:21:56,660 have learned with some additional Google specific tools. 457 00:21:56,660 --> 00:22:00,919 And then you have access to this wide platform full of APIs 458 00:22:00,919 --> 00:22:02,460 that's built right into the language. 459 00:22:02,460 --> 00:22:05,060 460 00:22:05,060 --> 00:22:08,330 And so I want to emphasize this isn't just about G Suite. 461 00:22:08,330 --> 00:22:12,210 It's a way to interact with a ton of different Google products. 462 00:22:12,210 --> 00:22:15,070 So you have all your favorites here like Sheets and Slides. 463 00:22:15,070 --> 00:22:19,560 But in addition to that, you can be using so many other things too. 464 00:22:19,560 --> 00:22:21,500 And we'll see a list in a second. 465 00:22:21,500 --> 00:22:25,160 But one more thing is that Apps Script can be used to create add-ons. 466 00:22:25,160 --> 00:22:27,050 And this is really exciting because you can 467 00:22:27,050 --> 00:22:29,930 modify the basic environment in which someone 468 00:22:29,930 --> 00:22:31,860 might be using a G Suite product. 469 00:22:31,860 --> 00:22:35,780 So for instance, in Google Docs, sometimes it's 470 00:22:35,780 --> 00:22:37,970 really helpful if I'm working on something 471 00:22:37,970 --> 00:22:42,050 that's mathematical to be able to type in a really sophisticated notation. 472 00:22:42,050 --> 00:22:46,100 For that, using LaTex is a great tool. 473 00:22:46,100 --> 00:22:48,740 And so there's an add-on for Google Docs where I can type 474 00:22:48,740 --> 00:22:50,880 in LaTex into a sidebar that appears. 475 00:22:50,880 --> 00:22:53,300 And then that can be inserted directly into my document. 476 00:22:53,300 --> 00:22:54,110 That's really neat. 477 00:22:54,110 --> 00:22:55,930 And what's especially new-- 478 00:22:55,930 --> 00:22:57,790 it came out just last week in fact-- 479 00:22:57,790 --> 00:22:59,120 our Gmail add-ons. 480 00:22:59,120 --> 00:23:02,450 So this is a way-- think of it as a Chrome extension for Gmail. 481 00:23:02,450 --> 00:23:05,000 This is a way that you can directly extend 482 00:23:05,000 --> 00:23:08,120 the Gmail UI to have custom things happen based 483 00:23:08,120 --> 00:23:09,880 on the contents of an email message. 484 00:23:09,880 --> 00:23:13,040 And so I'll give you an example of how I created one in the past 485 00:23:13,040 --> 00:23:15,686 and how you might be able to make one yourself. 486 00:23:15,686 --> 00:23:17,560 So that's like at the cutting edge right now. 487 00:23:17,560 --> 00:23:20,351 Highly recommend that you try that because it's such a new product, 488 00:23:20,351 --> 00:23:23,870 and there's a lot of room out there for exploration. 489 00:23:23,870 --> 00:23:26,780 But as I mentioned, there's so many Google services 490 00:23:26,780 --> 00:23:30,710 that can be used through Apps Script, not just the G Suite APIs. 491 00:23:30,710 --> 00:23:34,950 And so you can use Maps, YouTube, and a number of others. 492 00:23:34,950 --> 00:23:38,180 And to give you a full list, check this out. 493 00:23:38,180 --> 00:23:39,410 So a ton here. 494 00:23:39,410 --> 00:23:41,510 I'm not even going to go through all of them. 495 00:23:41,510 --> 00:23:43,730 But there's really so much you could be doing, 496 00:23:43,730 --> 00:23:46,770 especially when you try mixing and mashing them together. 497 00:23:46,770 --> 00:23:48,140 So how do you actually do this? 498 00:23:48,140 --> 00:23:49,655 So let's take a look at that. 499 00:23:49,655 --> 00:23:51,530 So we're going to start with an easy example. 500 00:23:51,530 --> 00:23:54,470 And then we'll work our way over to Gmail add-ons, 501 00:23:54,470 --> 00:23:59,420 that really new feature that I talking about that just came out last week. 502 00:23:59,420 --> 00:24:02,070 So before we actually see the code, I just 503 00:24:02,070 --> 00:24:06,290 want to give you some context as to what kinds of scripts you might be writing. 504 00:24:06,290 --> 00:24:07,970 And so just a few there-- 505 00:24:07,970 --> 00:24:11,660 we have standalone scripts, which are probably the most basic easiest way 506 00:24:11,660 --> 00:24:12,680 to get started. 507 00:24:12,680 --> 00:24:16,086 You can just go to script.google.com, and then start writing code. 508 00:24:16,086 --> 00:24:18,710 And then you have a little play button that appears at the top. 509 00:24:18,710 --> 00:24:21,200 And you van click that and have your functions execute. 510 00:24:21,200 --> 00:24:22,783 That's the easiest way to get started. 511 00:24:22,783 --> 00:24:24,210 No headache at all. 512 00:24:24,210 --> 00:24:28,310 But it's also really easy to go to a document, and then go to Tools, 513 00:24:28,310 --> 00:24:29,390 and then Script Editor. 514 00:24:29,390 --> 00:24:32,630 And so you can do this with Docs, Sheets, Slides, or Forms. 515 00:24:32,630 --> 00:24:35,930 Just go to the Tools menu in the normal UI, and then click on Script Editor. 516 00:24:35,930 --> 00:24:39,020 And then create a script that is bound to that specific document. 517 00:24:39,020 --> 00:24:43,370 And so what that means is for that particular Google Slides deck, 518 00:24:43,370 --> 00:24:46,520 you might be able to write a program that 519 00:24:46,520 --> 00:24:50,150 changes all the colors to black and white if that's what you want to do. 520 00:24:50,150 --> 00:24:52,970 And you can also use interface to create custom add-ons that 521 00:24:52,970 --> 00:24:56,855 can then be attached or opened up in a particular product such as Docs 522 00:24:56,855 --> 00:24:59,150 or Gmail as I mentioned before. 523 00:24:59,150 --> 00:25:00,120 That's one option. 524 00:25:00,120 --> 00:25:04,929 And then the last option is to create a full web app using Apps Script. 525 00:25:04,929 --> 00:25:07,220 I'm not really going to talk about that too much today. 526 00:25:07,220 --> 00:25:09,136 But all the documentation is available online. 527 00:25:09,136 --> 00:25:12,470 And if we understand the fundamentals from just creating standalone scripts 528 00:25:12,470 --> 00:25:16,510 and add-ons, you can extend that to creating your own web apps entirely 529 00:25:16,510 --> 00:25:17,840 through Apps Script. 530 00:25:17,840 --> 00:25:21,910 Remember, it's just JavaScript. 531 00:25:21,910 --> 00:25:24,490 So how would you actually create the project? 532 00:25:24,490 --> 00:25:27,280 As I mentioned, you go to Tools, Script Editor, 533 00:25:27,280 --> 00:25:31,120 and then you open up this IDE where you can specify 534 00:25:31,120 --> 00:25:32,680 what exactly you want to be doing. 535 00:25:32,680 --> 00:25:37,010 And so then let's actually try this hello world code. 536 00:25:37,010 --> 00:25:39,209 So it's really simple here. 537 00:25:39,209 --> 00:25:41,500 And in fact, both of these examples are equivalent just 538 00:25:41,500 --> 00:25:44,590 to highlight that you can write the JavaScript in a single line 539 00:25:44,590 --> 00:25:48,730 or you can spread it out where you have each call on a separate line. 540 00:25:48,730 --> 00:25:50,271 And you chain together these calls. 541 00:25:50,271 --> 00:25:53,020 And so what this is doing-- we open this up through a spreadsheet. 542 00:25:53,020 --> 00:25:54,670 So this is a document bound script. 543 00:25:54,670 --> 00:25:58,607 So I go to my spreadsheet tool Script Editor, and then I paste in this code. 544 00:25:58,607 --> 00:26:00,940 And just from reading this one line, what we're doing is 545 00:26:00,940 --> 00:26:04,610 we're getting the current sheet, refining what's in cell A1. 546 00:26:04,610 --> 00:26:06,350 So it's the top left corner. 547 00:26:06,350 --> 00:26:09,454 And then we're just going to set the contents of that cell to Hello World. 548 00:26:09,454 --> 00:26:10,870 All right, and let's try that out. 549 00:26:10,870 --> 00:26:16,270 550 00:26:16,270 --> 00:26:21,160 So I have-- actually, I'll come back to that in a second. 551 00:26:21,160 --> 00:26:24,400 That's simple enough, but I offer you a slightly more sophisticated example 552 00:26:24,400 --> 00:26:28,360 that will be, I think, a little bit more interesting. 553 00:26:28,360 --> 00:26:30,970 So this you just paste in the code editor. 554 00:26:30,970 --> 00:26:32,770 And then you hit the little play icon. 555 00:26:32,770 --> 00:26:35,189 And then it'll ask you first for permission. 556 00:26:35,189 --> 00:26:38,230 And so this is the really cool part about all the authorization happening 557 00:26:38,230 --> 00:26:38,944 under the hood. 558 00:26:38,944 --> 00:26:41,860 You don't have to worry about it, but Google takes care of it for you. 559 00:26:41,860 --> 00:26:45,250 You allow the application to do its trick. 560 00:26:45,250 --> 00:26:48,247 And then Hello World gets inserted in cell A1. 561 00:26:48,247 --> 00:26:50,330 And there's a video that talks about this as well. 562 00:26:50,330 --> 00:26:54,130 So you can take a look at that if you want a little more in-depth look 563 00:26:54,130 --> 00:26:54,870 at this snippet. 564 00:26:54,870 --> 00:26:57,560 565 00:26:57,560 --> 00:27:01,190 But before I show the example with the Maps interaction, 566 00:27:01,190 --> 00:27:05,120 let's just take a look at this toy example that shows you 567 00:27:05,120 --> 00:27:07,550 what you could be doing with Google Apps Script. 568 00:27:07,550 --> 00:27:10,430 So I'll give you a minute to read that. 569 00:27:10,430 --> 00:27:12,990 And then I can see what it does. 570 00:27:12,990 --> 00:27:16,070 So just take a second, process that. 571 00:27:16,070 --> 00:27:17,604 There's a lot going on here. 572 00:27:17,604 --> 00:27:20,270 But it's amazing that it's just using all these different Google 573 00:27:20,270 --> 00:27:21,230 products together. 574 00:27:21,230 --> 00:27:23,550 So give you a few seconds to look at that. 575 00:27:23,550 --> 00:27:26,532 576 00:27:26,532 --> 00:27:29,940 All right, now that you have some vague idea of what's going on, 577 00:27:29,940 --> 00:27:31,142 I'll parse through it. 578 00:27:31,142 --> 00:27:32,850 So what we're doing is we're starting out 579 00:27:32,850 --> 00:27:37,230 by just getting all the files that are Google Docs from Drive. 580 00:27:37,230 --> 00:27:39,510 So that uses both Drive and Docs. 581 00:27:39,510 --> 00:27:41,940 And then we're going through Contacts, and we're finding 582 00:27:41,940 --> 00:27:43,650 all the people in your address book. 583 00:27:43,650 --> 00:27:45,420 That's what the get contacts. 584 00:27:45,420 --> 00:27:48,120 And then we have this loop in JavaScript. 585 00:27:48,120 --> 00:27:51,510 And we're just iterating over all the documents that you got back. 586 00:27:51,510 --> 00:27:56,100 And we're getting the content from the documents as a string. 587 00:27:56,100 --> 00:28:00,510 And we are translating that from EN to CY, so from English to Cyrillic. 588 00:28:00,510 --> 00:28:02,070 So we translate all the documents. 589 00:28:02,070 --> 00:28:03,900 And for every document that we translate, 590 00:28:03,900 --> 00:28:05,733 we're going to iterate over all our friends, 591 00:28:05,733 --> 00:28:08,070 and we're going to send email with the document 592 00:28:08,070 --> 00:28:09,930 to every single one of our friends. 593 00:28:09,930 --> 00:28:13,080 So probably not the most useful script, but a very good example 594 00:28:13,080 --> 00:28:16,470 of how you can basically do whatever you want to do that 595 00:28:16,470 --> 00:28:17,730 involves Google products. 596 00:28:17,730 --> 00:28:20,239 Plus, you can also incorporate third party APIs 597 00:28:20,239 --> 00:28:21,780 if you really want to in Apps Script. 598 00:28:21,780 --> 00:28:24,020 So there's no limit there. 599 00:28:24,020 --> 00:28:26,070 But now the example that I really want to show-- 600 00:28:26,070 --> 00:28:28,903 it's a very small example, but I think it opens the door for so much 601 00:28:28,903 --> 00:28:30,200 more that you could be doing. 602 00:28:30,200 --> 00:28:32,110 So we have this spreadsheet. 603 00:28:32,110 --> 00:28:35,750 And it's going to have an address that we place in the spreadsheet. 604 00:28:35,750 --> 00:28:38,260 So this might be your user of your application. 605 00:28:38,260 --> 00:28:40,480 So they put in the address into the spreadsheet. 606 00:28:40,480 --> 00:28:42,063 And then you're going to run a script. 607 00:28:42,063 --> 00:28:44,830 And what the script will do is it's going to find 608 00:28:44,830 --> 00:28:46,950 whatever address is in the spreadsheet. 609 00:28:46,950 --> 00:28:49,690 And so that's what's the getRange A2-- 610 00:28:49,690 --> 00:28:50,800 that's what that's doing. 611 00:28:50,800 --> 00:28:51,300 And 612 00:28:51,300 --> 00:28:55,210 Then it's going to create a map and put a marker wherever the address is. 613 00:28:55,210 --> 00:28:58,690 And then, finally, it's going to get that URL for that map 614 00:28:58,690 --> 00:29:01,264 and stick it into the spreadsheet again. 615 00:29:01,264 --> 00:29:04,430 And so what that's going to do is it's going to create an example like this. 616 00:29:04,430 --> 00:29:08,110 And so here you have a little bit more going on with multiple markers. 617 00:29:08,110 --> 00:29:11,470 But you could easily write a loop that loops over the spreadsheet, and then 618 00:29:11,470 --> 00:29:15,505 places in a marker for every single address that a user has inputted. 619 00:29:15,505 --> 00:29:18,845 So let's see this in action. 620 00:29:18,845 --> 00:29:21,440 So I'm going to go back to my spreadsheet. 621 00:29:21,440 --> 00:29:24,180 And so I've already created the basic spreadsheet here. 622 00:29:24,180 --> 00:29:26,170 And since I live in Currier House at Harvard, 623 00:29:26,170 --> 00:29:28,040 I've put that in as the address. 624 00:29:28,040 --> 00:29:31,590 And then I'm going to go to Tools, Script Editor, 625 00:29:31,590 --> 00:29:34,450 and that brings us to our IDE. 626 00:29:34,450 --> 00:29:35,956 And so we have this file here. 627 00:29:35,956 --> 00:29:39,080 So the same exact code that you saw before-- we're getting the spreadsheet, 628 00:29:39,080 --> 00:29:40,288 finding the value in cell A2. 629 00:29:40,288 --> 00:29:42,050 So that's going to be Currier House. 630 00:29:42,050 --> 00:29:43,640 We are creating a map. 631 00:29:43,640 --> 00:29:45,980 And then we are getting the URL from the map 632 00:29:45,980 --> 00:29:49,040 and setting that value as what goes into cell B2. 633 00:29:49,040 --> 00:29:51,350 So I'm going to hit Run. 634 00:29:51,350 --> 00:29:53,480 And that should be it. 635 00:29:53,480 --> 00:29:54,950 So I go back to my spreadsheet. 636 00:29:54,950 --> 00:29:58,640 You see this link has been put in, and I click on the link. 637 00:29:58,640 --> 00:29:59,870 And there you go. 638 00:29:59,870 --> 00:30:01,790 That's where I live at Harvard. 639 00:30:01,790 --> 00:30:04,385 Pretty cool. 640 00:30:04,385 --> 00:30:05,540 So back to our deck. 641 00:30:05,540 --> 00:30:10,210 642 00:30:10,210 --> 00:30:11,680 You might want to extend this. 643 00:30:11,680 --> 00:30:14,110 So for instance, all it takes is one extra line. 644 00:30:14,110 --> 00:30:17,830 And then you can send an email through the Gmail interface 645 00:30:17,830 --> 00:30:20,634 and specify I just want to send a link to this person. 646 00:30:20,634 --> 00:30:21,550 And then there you go. 647 00:30:21,550 --> 00:30:25,060 And that email parameter right there that would just be some kind of JSON 648 00:30:25,060 --> 00:30:29,300 were you by the to, and the subject, and the contents of the message. 649 00:30:29,300 --> 00:30:31,300 And so you could easily put in the URL. 650 00:30:31,300 --> 00:30:33,910 And then have that sent off to one or even many friends 651 00:30:33,910 --> 00:30:37,410 from your address book. 652 00:30:37,410 --> 00:30:40,606 Another example-- suppose that you are a business owner, 653 00:30:40,606 --> 00:30:42,480 and then you publish a lot of YouTube videos. 654 00:30:42,480 --> 00:30:45,521 And you want to get some analytics on how those YouTube videos are doing. 655 00:30:45,521 --> 00:30:47,700 And so you might have an entire spreadsheet 656 00:30:47,700 --> 00:30:49,260 where these video IDs are logged. 657 00:30:49,260 --> 00:30:51,090 Or, perhaps, you have a Google Form. 658 00:30:51,090 --> 00:30:54,390 And that every time you upload a YouTube video, you paste in the ID. 659 00:30:54,390 --> 00:30:56,560 Or, even better, you could use the YouTube API 660 00:30:56,560 --> 00:30:59,400 that keeps track of any time that you upload a new video, 661 00:30:59,400 --> 00:31:01,350 and then puts the IDs in the spreadsheets. 662 00:31:01,350 --> 00:31:04,650 And then you could also use the YouTube API to get the title of the video, 663 00:31:04,650 --> 00:31:07,171 as well as how many views it's gotten. 664 00:31:07,171 --> 00:31:11,300 All right, and then all it takes is some Apps Script here. 665 00:31:11,300 --> 00:31:13,490 And then we have example videos that will 666 00:31:13,490 --> 00:31:16,370 go into more depth about how this actually works. 667 00:31:16,370 --> 00:31:18,500 But you'll see that in just five lines of code 668 00:31:18,500 --> 00:31:20,420 inside the function, that's all it really 669 00:31:20,420 --> 00:31:22,580 takes to get all the information. 670 00:31:22,580 --> 00:31:27,250 And then you just stick it right back into your spreadsheet. 671 00:31:27,250 --> 00:31:31,145 So let's talk about some potential use cases that you might want to be doing. 672 00:31:31,145 --> 00:31:33,270 I've alluded to some of them in a business context, 673 00:31:33,270 --> 00:31:34,704 but there's really so much. 674 00:31:34,704 --> 00:31:36,870 And I think Apps Script is for everyone, whether you 675 00:31:36,870 --> 00:31:39,420 want to write a simple script to get the job done once 676 00:31:39,420 --> 00:31:43,810 or write something more sustainable that serves an organization. 677 00:31:43,810 --> 00:31:47,367 OK, and so I've talked about some of the business use cases already. 678 00:31:47,367 --> 00:31:50,200 But in addition to that, perhaps you want to do stuff with calendars 679 00:31:50,200 --> 00:31:53,550 and maybe helping people share common resources. 680 00:31:53,550 --> 00:31:56,290 That's what the resource management bullet is all about. 681 00:31:56,290 --> 00:31:58,934 And so you might have a common room at Harvard 682 00:31:58,934 --> 00:32:00,850 that you want to allocate to different people. 683 00:32:00,850 --> 00:32:03,130 And so you could write a script that fairly allocates that. 684 00:32:03,130 --> 00:32:05,290 Or, maybe people send an email, and say, I want to book 685 00:32:05,290 --> 00:32:06,590 this room for a particular time. 686 00:32:06,590 --> 00:32:09,465 And then Apps Script will take care of it, update it on a spreadsheet 687 00:32:09,465 --> 00:32:12,160 or on a calendar, and then give you confirmation email. 688 00:32:12,160 --> 00:32:14,909 And there's a lot of automation that can be done with Apps Script. 689 00:32:14,909 --> 00:32:19,720 So maybe people are emailing in files to a particular Gmail alias. 690 00:32:19,720 --> 00:32:23,620 And then you are uploading those files from Gmail to Google Drive 691 00:32:23,620 --> 00:32:28,600 and keeping an organized file structure of all the permission 692 00:32:28,600 --> 00:32:31,160 slips that people are sending in for a field trip. 693 00:32:31,160 --> 00:32:34,450 And so there's more that you can do with reporting, so finding data 694 00:32:34,450 --> 00:32:38,440 periodically and then compiling beautiful spreadsheets or slide 695 00:32:38,440 --> 00:32:39,850 shows with that. 696 00:32:39,850 --> 00:32:41,950 And then the integration glue bullet-- that 697 00:32:41,950 --> 00:32:46,240 alludes to how you might be using these third party APIs from Twitter, 698 00:32:46,240 --> 00:32:48,640 a Salesforce, or something that I was using the other day 699 00:32:48,640 --> 00:32:50,864 was this website called Rebrandly. 700 00:32:50,864 --> 00:32:52,780 And Rebrandly is really neat in that it allows 701 00:32:52,780 --> 00:32:55,841 you to create customized short lengths for your domain. 702 00:32:55,841 --> 00:32:58,840 And so what I did was I created a Google Form that every time the Google 703 00:32:58,840 --> 00:33:01,330 form gets submitted, a certain trigger. 704 00:33:01,330 --> 00:33:05,390 So on Edit, whenever the spreadsheet tied to Google form-- 705 00:33:05,390 --> 00:33:05,890 excuse me. 706 00:33:05,890 --> 00:33:10,090 On Submit, anytime the Google form got submitted, a particular ActionScript 707 00:33:10,090 --> 00:33:10,990 got fired. 708 00:33:10,990 --> 00:33:15,040 And so what I did was I had a form that would let someone specify 709 00:33:15,040 --> 00:33:17,770 a long URL and then a short URL. 710 00:33:17,770 --> 00:33:19,130 And then they could-- 711 00:33:19,130 --> 00:33:21,370 for my student organization, every time they 712 00:33:21,370 --> 00:33:25,480 submit the form the long URL gets rerouted to the short URL using 713 00:33:25,480 --> 00:33:28,440 the Rebrandly API. 714 00:33:28,440 --> 00:33:30,089 So there's so much you could be doing. 715 00:33:30,089 --> 00:33:32,130 And I urge you to think about other ways that you 716 00:33:32,130 --> 00:33:37,570 might be serving your own organizations that matter in your life. 717 00:33:37,570 --> 00:33:40,000 Education is also a huge user of G Suite. 718 00:33:40,000 --> 00:33:43,060 We use it here at Harvard and plenty of other schools use it as well. 719 00:33:43,060 --> 00:33:45,310 And you might want to create some classroom management 720 00:33:45,310 --> 00:33:48,300 tools using Google Apps Script. 721 00:33:48,300 --> 00:33:52,290 And then a really popular one that a lot of people have been using 722 00:33:52,290 --> 00:33:54,660 is called Yet Another Mail Merge or YAMM. 723 00:33:54,660 --> 00:33:58,980 And this is a way to use a spreadsheet through an add-on. 724 00:33:58,980 --> 00:34:01,170 So you can go to the top menu and find an add-on 725 00:34:01,170 --> 00:34:03,780 and install YAMM or Yet Another Mail Merge. 726 00:34:03,780 --> 00:34:07,170 And then specify a message and then who you want to be sending it to. 727 00:34:07,170 --> 00:34:09,690 And then with one run of the script or with the add-on, 728 00:34:09,690 --> 00:34:12,600 you can send that customized message to many people in your inbox. 729 00:34:12,600 --> 00:34:15,510 And this is great if you're trying to do publicity or otherwise send 730 00:34:15,510 --> 00:34:18,949 a customized message to many people. 731 00:34:18,949 --> 00:34:21,040 And that's written using Google Apps Script. 732 00:34:21,040 --> 00:34:24,969 And then you can do other things such as like an out of office calendar 733 00:34:24,969 --> 00:34:29,230 for your team at the workplace. 734 00:34:29,230 --> 00:34:32,620 So just to recap, it's all just JavaScript. 735 00:34:32,620 --> 00:34:35,260 So that makes it incredibly easy. 736 00:34:35,260 --> 00:34:36,710 And it's done server side. 737 00:34:36,710 --> 00:34:39,010 So you don't even have to install anything locally. 738 00:34:39,010 --> 00:34:41,409 It's all done in Google's Cloud. 739 00:34:41,409 --> 00:34:42,580 It's different from node.js. 740 00:34:42,580 --> 00:34:46,900 So that is also server side, but not really what we're doing here. 741 00:34:46,900 --> 00:34:51,420 And you don't learn anything new because it is literally just JavaScript. 742 00:34:51,420 --> 00:34:54,480 You have access to all those amazing Google technologies that I've 743 00:34:54,480 --> 00:34:57,510 been talking about, but programmatic access in the way 744 00:34:57,510 --> 00:35:01,380 that you can have bulk actions taking place, and things that otherwise would 745 00:35:01,380 --> 00:35:04,935 be impossible, or at least extremely time consuming, such as creating 746 00:35:04,935 --> 00:35:08,070 100 slide decks at once. 747 00:35:08,070 --> 00:35:12,970 And then you have access to external resources too through third party APIs. 748 00:35:12,970 --> 00:35:14,890 But everything fells built in just by nature 749 00:35:14,890 --> 00:35:18,470 of how the language is structured, which is really neat. 750 00:35:18,470 --> 00:35:20,680 And you don't have to worry about deployment, 751 00:35:20,680 --> 00:35:22,554 or authentication, or anything like that. 752 00:35:22,554 --> 00:35:24,470 And there's so many things you could be doing, 753 00:35:24,470 --> 00:35:27,070 such as writing your own scripts, creating add-ons, 754 00:35:27,070 --> 00:35:30,130 or building your own web apps as well. 755 00:35:30,130 --> 00:35:32,636 So consider exploring all of that. 756 00:35:32,636 --> 00:35:34,510 But what we're going to do now is we're going 757 00:35:34,510 --> 00:35:37,690 to take a look at a Gmail add-on use case 758 00:35:37,690 --> 00:35:39,640 and how you might get started with that. 759 00:35:39,640 --> 00:35:42,940 So before I actually show the code that goes into a Gmail add-on, 760 00:35:42,940 --> 00:35:46,610 because it's so new, let me show you how a Gmail add-on actually works. 761 00:35:46,610 --> 00:35:49,310 So I'm going to navigate over to Gmail here. 762 00:35:49,310 --> 00:35:52,730 And I have this receipt that I've gotten from my friend Danny. 763 00:35:52,730 --> 00:35:57,606 So Danny paid me $8, and I might want to log that into a spreadsheet. 764 00:35:57,606 --> 00:35:59,480 And so you notice on the right-hand side this 765 00:35:59,480 --> 00:36:02,450 is what's new is that you have access to these little add-ons 766 00:36:02,450 --> 00:36:03,410 that you can click on. 767 00:36:03,410 --> 00:36:05,727 And then you can interact with in various ways. 768 00:36:05,727 --> 00:36:08,060 So the one that I built right here is called Expense It. 769 00:36:08,060 --> 00:36:09,520 And it looks like a little receipt. 770 00:36:09,520 --> 00:36:12,390 So I'm going to click on that, and let's see what happens. 771 00:36:12,390 --> 00:36:14,300 So we have this little form that appears. 772 00:36:14,300 --> 00:36:15,790 And so it says, log your expense. 773 00:36:15,790 --> 00:36:19,220 It has an expense ID based on how many times I've used this already. 774 00:36:19,220 --> 00:36:22,690 It finds the date of the expense through the email. 775 00:36:22,690 --> 00:36:24,440 So this email was sent from October 29. 776 00:36:24,440 --> 00:36:26,120 And so it finds that. 777 00:36:26,120 --> 00:36:30,650 How much the expense was-- so it reads my message, identifies that it was $8, 778 00:36:30,650 --> 00:36:32,350 finds out what the expense was about. 779 00:36:32,350 --> 00:36:35,180 So this is just based on the subject of the email. 780 00:36:35,180 --> 00:36:38,780 And then, finally, where the expense should be logged-- 781 00:36:38,780 --> 00:36:40,574 and that's just the URL of a spreadsheet. 782 00:36:40,574 --> 00:36:43,490 And I also have the option of creating a new spreadsheet if I want to. 783 00:36:43,490 --> 00:36:47,900 So perhaps I went on a business trip over the last weekend, 784 00:36:47,900 --> 00:36:51,980 and I want to compile all my expenses from that trip in particular. 785 00:36:51,980 --> 00:36:53,960 So then I can create a new spreadsheet. 786 00:36:53,960 --> 00:36:57,210 Maybe I'll call it weekend expenses. 787 00:36:57,210 --> 00:36:58,887 So I create the news sheet. 788 00:36:58,887 --> 00:37:01,220 So this is going to fire off through Google Apps Script. 789 00:37:01,220 --> 00:37:03,303 And then you'll see up top in green where it says, 790 00:37:03,303 --> 00:37:06,060 it's created the weekend expenses spreadsheet. 791 00:37:06,060 --> 00:37:09,860 And now that URL has been replaced down here, and I can submit my expense. 792 00:37:09,860 --> 00:37:11,501 When I submit my expense-- 793 00:37:11,501 --> 00:37:13,000 and then I can open the spreadsheet. 794 00:37:13,000 --> 00:37:14,360 So I've logged it successfully. 795 00:37:14,360 --> 00:37:15,930 Let me actually see that. 796 00:37:15,930 --> 00:37:17,840 And I'm going to open up the spreadsheet. 797 00:37:17,840 --> 00:37:19,250 And then there you go. 798 00:37:19,250 --> 00:37:21,830 Expense number 31 has been logged into this spreadsheet. 799 00:37:21,830 --> 00:37:23,660 It says that Danny paid me $8. 800 00:37:23,660 --> 00:37:24,200 Great. 801 00:37:24,200 --> 00:37:24,680 I have it there. 802 00:37:24,680 --> 00:37:27,170 And I can do that with all my emails to get my entire trip 803 00:37:27,170 --> 00:37:29,780 summarized in one spreadsheet. 804 00:37:29,780 --> 00:37:31,432 So that's the add-on in general. 805 00:37:31,432 --> 00:37:33,890 And you can imagine a lot of other possibilities with this. 806 00:37:33,890 --> 00:37:36,020 Perhaps, you might be an airline, and you 807 00:37:36,020 --> 00:37:39,537 want to allow users to check into your flight directly from within Gmail. 808 00:37:39,537 --> 00:37:41,870 So then you can have an add-on that appears on the side. 809 00:37:41,870 --> 00:37:44,870 And only when you have an email related to that particular airline, 810 00:37:44,870 --> 00:37:48,074 you can say check into the flight if it's 24 hours beforehand. 811 00:37:48,074 --> 00:37:50,240 And there's so many other things you could be doing. 812 00:37:50,240 --> 00:37:53,390 So really consider building this into your own workflow. 813 00:37:53,390 --> 00:37:56,680 And it might help with your productivity a ton. 814 00:37:56,680 --> 00:37:58,490 So how do you actually create that? 815 00:37:58,490 --> 00:38:00,350 So we go back to Apps Script. 816 00:38:00,350 --> 00:38:02,120 And so I have the code here already. 817 00:38:02,120 --> 00:38:03,690 I'll give you a quick tour of it. 818 00:38:03,690 --> 00:38:07,070 But there is also a video online on the Google Developers 819 00:38:07,070 --> 00:38:12,200 channel where I go into more depth about how you might create this add-on. 820 00:38:12,200 --> 00:38:17,140 So just to give you a brief overview, we have a few different files here. 821 00:38:17,140 --> 00:38:18,710 And so they're dot GS files. 822 00:38:18,710 --> 00:38:19,970 But it's still JavaScript. 823 00:38:19,970 --> 00:38:22,462 It's just Google Apps Script layered on top of that. 824 00:38:22,462 --> 00:38:24,920 And so the one that I want to bring your attention to first 825 00:38:24,920 --> 00:38:27,220 is this appsscript.json file. 826 00:38:27,220 --> 00:38:29,060 And so this is called the manifest file. 827 00:38:29,060 --> 00:38:32,660 And it's basically where you specify the general metadata that's 828 00:38:32,660 --> 00:38:34,220 associated with this add-on. 829 00:38:34,220 --> 00:38:37,610 So you specify what scopes you might want to be using. 830 00:38:37,610 --> 00:38:40,520 And then you also specify this really important part 831 00:38:40,520 --> 00:38:45,140 here is what function gets triggered when the add-on gets started. 832 00:38:45,140 --> 00:38:48,440 And so I have this function called get contextual add-on that's 833 00:38:48,440 --> 00:38:51,180 going to happen when the add-on is first used. 834 00:38:51,180 --> 00:38:54,440 So I'm going to jump over to get contextual add-on. 835 00:38:54,440 --> 00:38:57,940 And so that's this function right here. 836 00:38:57,940 --> 00:39:00,460 And it's calling a lot of other functions that I wrote, 837 00:39:00,460 --> 00:39:03,520 but you get a sense of the overall gist of what's going on. 838 00:39:03,520 --> 00:39:06,940 And what's happening is that we are customizing what 839 00:39:06,940 --> 00:39:08,530 card should be displayed to the user. 840 00:39:08,530 --> 00:39:12,040 So the card is that UI that you see on the right-hand side. 841 00:39:12,040 --> 00:39:14,174 And then we're building that card and returning it 842 00:39:14,174 --> 00:39:15,340 so that the user can see it. 843 00:39:15,340 --> 00:39:17,980 And you can have add-ons that have multiple cards. 844 00:39:17,980 --> 00:39:21,610 And then you would just return an array of those various cards. 845 00:39:21,610 --> 00:39:24,040 And then the user can go between the different cards. 846 00:39:24,040 --> 00:39:27,400 And Google takes care of that UI for you. 847 00:39:27,400 --> 00:39:30,770 So the general idea is that we're getting the message. 848 00:39:30,770 --> 00:39:32,990 And then we're figuring out what the date was 849 00:39:32,990 --> 00:39:36,430 in the message, how much money was on the receipt, 850 00:39:36,430 --> 00:39:38,191 as well as what the message was about. 851 00:39:38,191 --> 00:39:39,940 And then we put all those things together. 852 00:39:39,940 --> 00:39:42,100 We create the card. 853 00:39:42,100 --> 00:39:43,090 And then we build it. 854 00:39:43,090 --> 00:39:46,610 And we send it over so that the user can actually see it. 855 00:39:46,610 --> 00:39:48,700 So suppose you write all this code. 856 00:39:48,700 --> 00:39:52,000 And then you can find the actual code on GitHub if you want to try it yourself. 857 00:39:52,000 --> 00:39:55,000 But how would you actually deploy the add-on to get it working yourself? 858 00:39:55,000 --> 00:39:57,970 And so you can publish it to the G Suite Marketplace 859 00:39:57,970 --> 00:40:00,940 where someone else from anywhere in the world can install your add-on. 860 00:40:00,940 --> 00:40:02,360 That say you just want to test it on your own. 861 00:40:02,360 --> 00:40:03,860 This is great for a final project. 862 00:40:03,860 --> 00:40:05,500 If you're just debugging or you want to make 863 00:40:05,500 --> 00:40:08,249 sure things are working on your own machine first, what you can do 864 00:40:08,249 --> 00:40:09,970 is you can deploy from Manifest. 865 00:40:09,970 --> 00:40:12,730 And so that's just looking at this appsscript.json file, 866 00:40:12,730 --> 00:40:15,820 figuring out what it's all about, and then you can install it directly 867 00:40:15,820 --> 00:40:17,140 into your own Gmail. 868 00:40:17,140 --> 00:40:20,560 And so what you do is you go deploy for Manifest. 869 00:40:20,560 --> 00:40:23,710 You can create a deployment. 870 00:40:23,710 --> 00:40:25,980 So we might call this Test. 871 00:40:25,980 --> 00:40:27,660 Going to save that. 872 00:40:27,660 --> 00:40:29,360 And then you can get an ID. 873 00:40:29,360 --> 00:40:31,080 And so you would get this ID. 874 00:40:31,080 --> 00:40:34,410 And then you would go into Gmail, and then you can go to Settings. 875 00:40:34,410 --> 00:40:38,370 And then you can copy and paste the ID into the Gmail add-ons part 876 00:40:38,370 --> 00:40:39,120 of settings. 877 00:40:39,120 --> 00:40:42,627 And then you have the add-on appear on the right-hand side in your own emails. 878 00:40:42,627 --> 00:40:44,460 But if you want to release this more widely, 879 00:40:44,460 --> 00:40:47,130 then you have to publish it through the G Suite Marketplace, which 880 00:40:47,130 --> 00:40:48,220 is very doable on its own. 881 00:40:48,220 --> 00:40:50,900 But I'm not going to go into that right now. 882 00:40:50,900 --> 00:40:53,840 And as a last point, I strongly recommend 883 00:40:53,840 --> 00:40:55,724 if you're interested in making a Gmail add-on 884 00:40:55,724 --> 00:40:57,390 that you try going through this example. 885 00:40:57,390 --> 00:41:06,080 So I've created the Code Lab available at g.co/codelabs/gmail-add-ons. 886 00:41:06,080 --> 00:41:08,150 And so this Code Lab will teach you step by step 887 00:41:08,150 --> 00:41:10,820 how you would build that add-on that I just 888 00:41:10,820 --> 00:41:13,220 showed you for logging your expenses. 889 00:41:13,220 --> 00:41:16,420 And so it'll go through a lot of interesting stuff about Apps Script 890 00:41:16,420 --> 00:41:16,920 as well. 891 00:41:16,920 --> 00:41:18,410 So even if you're not looking to make a Gmail add-on, 892 00:41:18,410 --> 00:41:20,420 I think this is a great way to learn Apps Script. 893 00:41:20,420 --> 00:41:21,620 You'll work with spreadsheets. 894 00:41:21,620 --> 00:41:23,328 You'll work with what's called a property 895 00:41:23,328 --> 00:41:26,510 store, which allows you to store data in between executions of the script 896 00:41:26,510 --> 00:41:27,270 as well. 897 00:41:27,270 --> 00:41:29,330 So this is a great way to learn about creating 898 00:41:29,330 --> 00:41:31,100 a Gmail add-on, any other kind of add-on, 899 00:41:31,100 --> 00:41:33,690 or just using Apps Script itself. 900 00:41:33,690 --> 00:41:38,672 All right, so with that, let's just wrap up. 901 00:41:38,672 --> 00:41:40,130 So I've already summarize all this. 902 00:41:40,130 --> 00:41:42,030 So let me just jump through that. 903 00:41:42,030 --> 00:41:45,830 904 00:41:45,830 --> 00:41:46,550 Cool. 905 00:41:46,550 --> 00:41:48,600 So how do you keep going from there? 906 00:41:48,600 --> 00:41:52,770 So there are a lot of videos and blog posts available online. 907 00:41:52,770 --> 00:41:55,480 Another really great resource that my mentor created 908 00:41:55,480 --> 00:41:57,950 is called the Core Python Programming Blog. 909 00:41:57,950 --> 00:42:00,760 And he writes out lots of code snippets like you 910 00:42:00,760 --> 00:42:02,510 saw at the very beginning with the YouTube 911 00:42:02,510 --> 00:42:06,410 or the Slides API that explain how you can be using the APIs through Python. 912 00:42:06,410 --> 00:42:08,720 But if you want to be using something else like Java, 913 00:42:08,720 --> 00:42:11,969 you can also look at those examples and then extend it into your own language. 914 00:42:11,969 --> 00:42:15,200 And so that's a great way to look at the APIs. 915 00:42:15,200 --> 00:42:17,840 But then you can also look at Apps Script 916 00:42:17,840 --> 00:42:20,390 on the developers.google website. 917 00:42:20,390 --> 00:42:22,340 And we have a lot of videos as well. 918 00:42:22,340 --> 00:42:25,140 If you just search for the G Suite Dev Show on YouTube, 919 00:42:25,140 --> 00:42:27,260 you'll find a ton of really great videos that 920 00:42:27,260 --> 00:42:31,200 talk about different code examples in-depth for five or six minutes. 921 00:42:31,200 --> 00:42:32,720 Try out the Code Lab. 922 00:42:32,720 --> 00:42:35,120 In addition to the Gmal Add-Ons Code Lab, 923 00:42:35,120 --> 00:42:39,290 there's also a code lab in the Sheets API as well as the Slides API. 924 00:42:39,290 --> 00:42:42,020 And both of those I believe are written using Node. 925 00:42:42,020 --> 00:42:44,270 So if you are a Node or JavaScript person, 926 00:42:44,270 --> 00:42:47,240 that's a great place to turn to. 927 00:42:47,240 --> 00:42:49,800 And then there a lot of documentation available as well. 928 00:42:49,800 --> 00:42:51,170 So take a look at that website. 929 00:42:51,170 --> 00:42:54,140 But then also feel free to turn to Stack Overflow. 930 00:42:54,140 --> 00:42:57,530 And we also have a Google page where you can check out the community 931 00:42:57,530 --> 00:42:59,210 and ask questions there. 932 00:42:59,210 --> 00:43:01,370 So I hope that helps. 933 00:43:01,370 --> 00:43:02,690 And I'll leave it at that. 934 00:43:02,690 --> 00:43:05,600 If you have any questions in the audience, feel free to ask me now. 935 00:43:05,600 --> 00:43:09,140 And anything online, just leave a note on YouTube. 936 00:43:09,140 --> 00:43:10,490 So thanks for tuning in. 937 00:43:10,490 --> 00:43:11,930 These slides are available online. 938 00:43:11,930 --> 00:43:14,990 And I hope you've learned something that you can use in real life. 939 00:43:14,990 --> 00:43:16,540 Thanks. 940 00:43:16,540 --> 00:43:17,638