Google Apps Script and G Suite APIs, by Sundar Solai

SUNDAR SOLAI: Hello, everybody My name is Sundar Welcome to the CS50 seminar It’s great to see so many people here in person And hello to everyone tuning in online as well So just a little bit about myself before we get started So, like I said, my name is Sundar I’m a junior here at Harvard, and I live in Currier House I study computer science, and I also really love statistics I was on CS50 staff last year as a teaching fellow And I’m really happy to be back and sharing this technology through Google with a lot of there really useful APIs I spent this past summer interning at Google in California, where I was on the G Suite team And I’ll tell you a lot more about the various APIs that we have and how you can use those in your own final projects, or whatever else you might be working on So let’s get started OK, so what is G Suite? It’s essentially a platform of all your favorite Google applications, including but not limited to what you see here, including Gmail, Calendar, Docs, Sheets, Slides, Forms and all these other really useful tools for productivity And so G Suite has both the consumer applications that you’re used to, but, also, a big part of it is the enterprise solutions So, for instance, at college we have @college.harvard.edu email addresses, which are done through G Suite And so all the services that we use have Google products that tie into them So, for instance, I could look at my college calendar through Google Calendar And, today, the focus is going to be on the various APIs that you can use to programmatically interact with G Suite So in addition to being probably a user of these products, you can be a developer and incorporate programmatic interactions with these platforms, so that users of your own applications might be able to generate spreadsheets on the fly Or, once a Google form gets submitted, perhaps a certain action takes place every time someone submits a form And so we’ll talk about different examples like that And then you can brainstorm on your own to see how that might work into your own workflows So I’m going to spend the first part of this talk describing how you might interact with the APIs in the traditional way And then we’ll talk about Google Apps Script, which is this really amazing– and I’m surprised by how many people still haven’t heard of it because it’s fabulous in how quickly you can interact with the Google APIs without really having to do any overhead in getting started So we’ll talk about the traditional way first And then we’ll get into that too So say I want to create a project, and I want to use the YouTube API So how would I do that? So the first step is to navigate to console.developers.google.com And this is the Developer Console where you can create a project So you see here there’s that Select a Project dropdown And you can either use an existing project or create a new one So you navigate there and do whatever is appropriate And then you can enable whichever APIs you think you might be using in your application And so you’ll see here there are really a ton of APIs available I think since I created this slide the interface has actually changed a tiny bit But the point remains that there are a lot of APIs from Android, to YouTube, to G Suite that you can just flip on and then you can get the credentials to actually use those APIs in your application So this is in the Library tab that you see here But once you enable the APIs, then you can get the credentials at the next step And so once you get the credentials, you can download what’s called an API key And then use that to prove to Google, hey, it’s me I’m going to be using the Google Drive API Let me read files from the Drive So you do that And now I’m going to show some Python examples of how you might actually do this off process to prove to Google you are indeed who you say you are, and therefore, you should have access to the API So there’s two different kinds of off that you could be doing, either simple or authorized And so I’ll point out the distinction here and then we’ll dig in a little bit to what this code actually does and what the differences are So, in one case, the simpler case, you have simple API access And this is for things such as the YouTube Data API where the point of you interacting with the API is not to do anything that’s really user specific, so more just general I want to search YouTube and show the top 10 cat videos or something like that And on the other hand, you might need more sophisticated authorization because you might be parsing a user’s Gmail messages and then creating calendar events based on that And so that requires a higher level access to what the user actually wants to be doing And so for that reason, you’re going to need to do a little bit more in the boiler plate So let’s actually take a look at this So these examples are in Python, but that doesn’t mean that you’re restricted to Python In fact, you can basically use any programming language you want And the Google API client library should be available for that And you can always use with HTTP, get and post requests as well So looking at the simple API access boilerplate, it’s really only three lines So first we import the API client

So that’s what you can install through Google So in Python, you just say something like pip install and then Google API client libraries or something like that And this is all available on the website on developers.google.com So once you have that installed, you’d import it And then back to those credentials that I was showing earlier in the developer console, you can get an API key from there And so this is some very long string that is unique to you and shows Google that you are whichever user is trying to use a particular API So you’d paste in that key here And something that I’ll point out is that if you’re writing an actual application that you intend to be used by many people, for security purposes, you probably don’t want your API key just sitting around in the source code That’s something that’s best kept in a more secure place that you then pull in over here But it shouldn’t just be plainly visible to everybody But you put that in nonetheless And then finally, you do this in line eight– the SERVICE= discovery.build, and then you specify what kind of API you want to be using And so the idea here is that as a string that first parameter you’re stating, I want to use the YouTube API And then specify what version And then it’s pulling in the key that you said earlier as that third argument And then together what you’re getting back is this actual API client that you can then do various function calls from, such as searching YouTube for your favorite cat videos OK, so let’s keep going On the other hand, like I mentioned, we have authorized API access And so it’s a little bit more sophisticated what’s going on here I’m not going to delve into it too deep, but just the points that you would need to get started on your own applications Because what I hate the most is we go through CS50, and we all become these rock star programmers But we get limited by the actual boilerplate that’s needed to get started So try using this And to give you some general sense of what’s going on, we’re doing our imports at the top But then line 5 is key So this line that says SCOPES– what we’re doing there is we’re specifying what parts of the APIs we want to be using And so in addition to saying I want to use the Drive API, you might provide one or more specific scopes within that API So for instance, you might be writing an application that needs only to read files from Drive and doesn’t request any rights from the user And so if that’s the case, then you’d want to use the drive.readonly scope And there are similar scopes in Gmail, and Slides, and other G Suite and Google API products And so the advantage of using the tightest scope possible is that when the dialog appears for the user to verify, yes, I’d like this application to have access to my drive files, it’s more secure for the user because they don’t have to give full access to the files They only need to give read access, or write access, or whatever you actually need for the application So that’s just a good practice And so after you establish for scopes, you go through this off flow in lines 9 to 13 But then once you get through that, at the end of the day, you’re still building the service like you did before And so after this top section, then you can get your actual application, which is the fun part I’ll just point out that you can use multiple scopes So you’re not limited to a single scope And you can say I want to use Drive, I want to use Sheets, I want to use Slides and create a huge integration So that’s really exciting too And now let’s talk about some examples of what you can do with the API And if the live demo gods are on my side, we’ll actually see some examples of these scripts in action So the first one that we’re going to talk about is this searching YouTube for videos And so what’s going on here– this is a simple API access because all we’re doing is searching We’re not requiring anything about the user’s identity And so we just use the API key as before And then what we do is we have this section from lines 5 to 8 that’s basically helping us print out what videos we uncover But the key part here and what I really want you to focus on with actually interacting with the API is that in line 10 after we get access to the YouTube API, in line 11, that’s where we’re doing the actual search And so you’ll see that we’re going YOUTUBE.search And then within dot search, we have this method called list And so with list, you can specify what exactly you’re trying to search for And so we do that here with the query And so if you look at what capital query has actually been established as in line 5, we see that it’s Python And so what this is doing is it’s searching YouTube for videos related to Python And then in lines 14 to 17 this is all just normal Python It has nothing to do with the API themselves We’re just iterating through what we get back that was stored as the result or R-E-S, Res And then we iterate over that And we just print out every YouTube video that we uncover So let’s take a look at this in action So I will close out of the slides for a second

OK So I have this example script pulled up here just to show you It’s the same exact thing I made one slight change And that was instead of having query be Python, I have it as sys.rv1 And so this just looks at the command line arguments when I call the script and looks at the first one that we supply And so you’ll notice here that these scripts are very easy to modify And if you know Python, you can do really whatever you want with them So use the API as an access point to these Google technologies, but then bring in your own creativity to do whatever you really want to do The sky’s the limit when it comes to programming So let’s actually run this So the way I run it is Python, and the name of the script, and then whatever I want to search for So for instance, I might want to search for videos on CS50 So I do that, and let’s see what we get back I’m having some issues with my Python 3 So I’m going to use Python 2 But this script should work for either one I just had a package installation error So let’s do this with Python 2 It’s searching And then there we go We get back top five videos on CS50 Cool So let’s go back to our examples here So that was an example of simple API access And now let’s touch on a more sophisticated example, where you actually need to get the user to go into their Google Drive account or rather have the API go into a user’s Google Drive account And so the boilerplate is very similar to what I showed earlier And you’ll see here that we’re using the read-only scope from Google Drive And then the action happens in line 14 So in line 14, we get back– we build the service And then in line 15 we’re actually listing the files that we want And so what this is doing is that it lists all the files that someone has And then it iterates in line 16 and 17 over those files that come back and just prints out their name All right You can also do things with the Sheets and Slides So the Slides API– I think it came out maybe a year or a year and a half ago Really exciting, and you can think of a lot of neat use cases for this So for instance, suppose I were to give a lot of talks like this, but because I do them in different locations, the title slide needs to reflect where I’m giving the talk Or, perhaps, I could just create a script that would take a template deck and then edit the title slide so that it fits whatever talk I’m going to be giving that day So you can imagine these customized presentations You might be a executive or reporting to an executive at a business And you’d want to give a slide deck every quarter with the performance for the company And so you can create charts maybe in Google Sheets, and then have those sent right into Slides every quarter for your presentation to the boss And we have a really cool example on GitHub that is a converter from markdown to Google Slides, so check that out too So the example that I’ll show now is the ability to create a template deck, put in some placeholder text or shapes, and then replace those placeholders with images or text that you really want to use And so this is useful again for that use case where you might be creating the same or similar presentation for a lot of different spaces, and so being able to start with one common template and then going from there And so we’ll see in this example with the Slides API, and it’s very similar in the Sheets API, among a few others that the requests that you create– so what you actually want to be doing to interact with your slide deck or to interactive spreadsheet goes in this JSON like structure And so in Python, it’s a dictionary So we have an array or a list, I should say, of requests And each one is this JSON-esque blob And so you’ll see here that we have these two specific requests happening Replace all text, and replace all shapes with image And so the first part here is finding the title, and then replacing that with hello world And then the second part is looking for something that says logo and sticking in a particular image that we want to include And then while we create those requests, they don’t actually get executed until you use the batch update command And so that’s key here is that we create all requests at once And then we send them over using batch update And this is really useful because rather than having to ping the API hundreds of times, you can bundle all your requests together and then do it in one shot And so this is helpful to help avoiding hitting the API limit that is imposed on these APIs to make sure that you’re using them reasonably So let’s try this in action I have a modified version of the script So head over to my terminal I think I called it slides.py So I’ll show you the entire script before we run it So there’s a lot more code here, but much of it is just that same off flow that you’ve seen earlier So we have that in the beginning And then I’ll just point out here we’re going to be using an image file that I have stored on Google Drive called logo.png

And then I’m going to be using a template file called Slides Example So the script is going to duplicate my Slides Example a slide show And then I’m going to modify that new slide show in order to have the logo picture, as well as the text that I want to include And so because I’m going to be copying a file in Google Drive, I’m going to actually need the drive scope here So I have that listed first And then I also have the presentation scope so that I can do the modifications on the slide deck once I’ve copied it So I go through, and I use my discovery.build to get my drive and my slides access And then what we have down here is we’re looking through Drive So we’re listing all files that have the name of the template file And the template file I think I called it Slides Example So we go through Drive, and we find anything that’s called Slides Example And then you see here at the end of the line we have this bracket zero that gets us the first element in the list So Python is zero indexed And so that will get us the first document or first file that is named slide’s example So we do that And then what we’re going to do is we’re going to use the Drive API again in line 25 to copy that original file and create a new one called Google Slides API Template Demo, which we specified over here So we copy that, right? But now all we have is a duplicate of that original slide deck So what we want to do is we want to edit that and replace the contents of that slide deck with the customized information that we specified up top So we have to find first of all where the rectangle placeholder is that we’re going to be replacing in order to include the new image, that logo.png So here we use the Slides API, and then we find the first slide So we’re getting all the slides And then we find the first one using bracket zero And then we iterate over all the elements on the slide until we find something that is of the shape rectangle So that’s what’s going on there Then what we do is we go back to the Drive API, and we find whatever image is called logo.png because that’s what I specified that I want to be using And then finally, once we have identified all those key components, we actually need to put them together And so here you’ll see those requests that I was talking about earlier And so the idea is that we are doing both the replacement of the placeholder text with the text hello world And that we’re also going to be replacing the rectangle with the image, the logo picture, that I’ve been talking about And that image is just going to fit into the exact same space that the rectangle was in originally And then, finally, we use our batch update to actually make that happen And then we print out done because we’re all done OK, so let’s try this out So I’ll just show you the template slide deck first So that we have here it’s called Slides Example All right, and now I’m going to go back to my terminal and actually run the script So this one is Python, slides.py And let’s see if that works So it’s copying It’s finding everything And then it’s replacing And now it’s done so I’m going to navigate back to My Drive And there we go We have a new deck that has just been created at 9:55 AM So I’m going to open that up And there we go So the CS50 logo– that’s floating up there And then we also have hello world that has replaced the text that we had on the original slide deck Pretty cool, right? So this is a very simple toy example, but I challenge you to explore a lot further with that and turn it into something that’s really useful for a problem that you have in your own life And like I said earlier, it’s very feasible to integrate multiple APIs together and create a tool that might go into Sheets, get data, turn that into charts, and then put that into a deck Back to this So I’ve been talking about the Google Sheets API as well This is a really powerful API And I’ll show you a project that I did with it in the second But I’ve been mentioning you can do customized reporting You can also have data come out of Sheets So perhaps you have people logging things into a Google Form And then you want to take that data from Sheets and then move it somewhere else And so you can do that programmatically with the Sheets API And to give you an example of something that I worked on personally with this, I used a really neat tool called Google Big Query, which also has a very useful API And what’s cool about that is that you have access to these enormous data sets gigabytes or larger in size And you can query them in seconds or even fractions of a second using familiar SQL command So I think by this time in CS50 you should be learning about SQL, which is this really friendly language for pulling out information from databases And so here what I did was I used Google Big Query It comes with these really neat example data sets, so I took the pitch by pitch data for every pitch

thrown in the 2016 MLB season, which is pretty topical at the moment in fact And so I took all that data and I aggregated it into dashboards for every team in the MLB so that we can compare how different pitchers are doing and how different hitters are doing And then I applied conditional formatting to every different column and created this heat map where you can see who is excelling and who’s not And then there are other aspects to this project such as a chart that shows who’s throwing the most fastballs or who’s throwing the most screwballs And so it’s a great way to visualize data through a spreadsheet All right, so enough on that I’m going to shift gears now to describing Google Apps Script Apps Script is this really neat, powerful platform by which you can interact with the Google APIs without having to go through any of the headache that comes along with the off process And it just feels like a much more native approach to dealing with Google products So it’s really easy to get started And we’ll do some neat examples today as well So what exactly is Apps Script? Well, it’s symbolized by this icon And it’s just a new flavor of JavaScript, if you will It takes away the API flavor So whatever we’ve been seeing earlier with Python or whatever other language you might be using, you don’t actually have to use the Google API as an API It’s as if it’s built in to the environment And what makes that really nice is that you don’t have to worry about setting up anything with Auth Things just work right out of the box It’s super friendly You don’t have to install any packages Everything just works And it’s all done on the web And there’s an IDE found at the script.google.com where you can get coding right now And the thing I really want to emphasize is that it’s literally just JavaScript And so in CS50 you will be, if you haven’t already, working with JavaScript And so you can apply all those ideas that you have learned with some additional Google specific tools And then you have access to this wide platform full of APIs that’s built right into the language And so I want to emphasize this isn’t just about G Suite It’s a way to interact with a ton of different Google products So you have all your favorites here like Sheets and Slides But in addition to that, you can be using so many other things too And we’ll see a list in a second But one more thing is that Apps Script can be used to create add-ons And this is really exciting because you can modify the basic environment in which someone might be using a G Suite product So for instance, in Google Docs, sometimes it’s really helpful if I’m working on something that’s mathematical to be able to type in a really sophisticated notation For that, using LaTex is a great tool And so there’s an add-on for Google Docs where I can type in LaTex into a sidebar that appears And then that can be inserted directly into my document That’s really neat And what’s especially new– it came out just last week in fact– our Gmail add-ons So this is a way– think of it as a Chrome extension for Gmail This is a way that you can directly extend the Gmail UI to have custom things happen based on the contents of an email message And so I’ll give you an example of how I created one in the past and how you might be able to make one yourself So that’s like at the cutting edge right now Highly recommend that you try that because it’s such a new product, and there’s a lot of room out there for exploration But as I mentioned, there’s so many Google services that can be used through Apps Script, not just the G Suite APIs And so you can use Maps, YouTube, and a number of others And to give you a full list, check this out So a ton here I’m not even going to go through all of them But there’s really so much you could be doing, especially when you try mixing and mashing them together So how do you actually do this? So let’s take a look at that So we’re going to start with an easy example And then we’ll work our way over to Gmail add-ons, that really new feature that I talking about that just came out last week So before we actually see the code, I just want to give you some context as to what kinds of scripts you might be writing And so just a few there– we have standalone scripts, which are probably the most basic easiest way to get started You can just go to script.google.com, and then start writing code And then you have a little play button that appears at the top And you van click that and have your functions execute That’s the easiest way to get started No headache at all But it’s also really easy to go to a document, and then go to Tools, and then Script Editor And so you can do this with Docs, Sheets, Slides, or Forms Just go to the Tools menu in the normal UI, and then click on Script Editor And then create a script that is bound to that specific document And so what that means is for that particular Google Slides deck, you might be able to write a program that changes all the colors to black and white if that’s what you want to do And you can also use interface to create custom add-ons that can then be attached or opened up in a particular product such as Docs or Gmail as I mentioned before That’s one option

And then the last option is to create a full web app using Apps Script I’m not really going to talk about that too much today But all the documentation is available online And if we understand the fundamentals from just creating standalone scripts and add-ons, you can extend that to creating your own web apps entirely through Apps Script Remember, it’s just JavaScript So how would you actually create the project? As I mentioned, you go to Tools, Script Editor, and then you open up this IDE where you can specify what exactly you want to be doing And so then let’s actually try this hello world code So it’s really simple here And in fact, both of these examples are equivalent just to highlight that you can write the JavaScript in a single line or you can spread it out where you have each call on a separate line And you chain together these calls And so what this is doing– we open this up through a spreadsheet So this is a document bound script So I go to my spreadsheet tool Script Editor, and then I paste in this code And just from reading this one line, what we’re doing is we’re getting the current sheet, refining what’s in cell A1 So it’s the top left corner And then we’re just going to set the contents of that cell to Hello World All right, and let’s try that out So I have– actually, I’ll come back to that in a second That’s simple enough, but I offer you a slightly more sophisticated example that will be, I think, a little bit more interesting So this you just paste in the code editor And then you hit the little play icon And then it’ll ask you first for permission And so this is the really cool part about all the authorization happening under the hood You don’t have to worry about it, but Google takes care of it for you You allow the application to do its trick And then Hello World gets inserted in cell A1 And there’s a video that talks about this as well So you can take a look at that if you want a little more in-depth look at this snippet But before I show the example with the Maps interaction, let’s just take a look at this toy example that shows you what you could be doing with Google Apps Script So I’ll give you a minute to read that And then I can see what it does So just take a second, process that There’s a lot going on here But it’s amazing that it’s just using all these different Google products together So give you a few seconds to look at that All right, now that you have some vague idea of what’s going on, I’ll parse through it So what we’re doing is we’re starting out by just getting all the files that are Google Docs from Drive So that uses both Drive and Docs And then we’re going through Contacts, and we’re finding all the people in your address book That’s what the get contacts And then we have this loop in JavaScript And we’re just iterating over all the documents that you got back And we’re getting the content from the documents as a string And we are translating that from EN to CY, so from English to Cyrillic So we translate all the documents And for every document that we translate, we’re going to iterate over all our friends, and we’re going to send email with the document to every single one of our friends So probably not the most useful script, but a very good example of how you can basically do whatever you want to do that involves Google products Plus, you can also incorporate third party APIs if you really want to in Apps Script So there’s no limit there But now the example that I really want to show– it’s a very small example, but I think it opens the door for so much more that you could be doing So we have this spreadsheet And it’s going to have an address that we place in the spreadsheet So this might be your user of your application So they put in the address into the spreadsheet And then you’re going to run a script And what the script will do is it’s going to find whatever address is in the spreadsheet And so that’s what’s the getRange A2– that’s what that’s doing And Then it’s going to create a map and put a marker wherever the address is And then, finally, it’s going to get that URL for that map and stick it into the spreadsheet again And so what that’s going to do is it’s going to create an example like this And so here you have a little bit more going on with multiple markers But you could easily write a loop that loops over the spreadsheet, and then places in a marker for every single address that a user has inputted So let’s see this in action So I’m going to go back to my spreadsheet And so I’ve already created the basic spreadsheet here And since I live in Currier House at Harvard, I’ve put that in as the address And then I’m going to go to Tools, Script Editor, and that brings us to our IDE And so we have this file here So the same exact code that you saw before– we’re getting the spreadsheet, finding the value in cell A2 So that’s going to be Currier House We are creating a map And then we are getting the URL from the map and setting that value as what goes into cell B2 So I’m going to hit Run And that should be it So I go back to my spreadsheet You see this link has been put in, and I click on the link And there you go That’s where I live at Harvard

Pretty cool So back to our deck You might want to extend this So for instance, all it takes is one extra line And then you can send an email through the Gmail interface and specify I just want to send a link to this person And then there you go And that email parameter right there that would just be some kind of JSON were you by the to, and the subject, and the contents of the message And so you could easily put in the URL And then have that sent off to one or even many friends from your address book Another example– suppose that you are a business owner, and then you publish a lot of YouTube videos And you want to get some analytics on how those YouTube videos are doing And so you might have an entire spreadsheet where these video IDs are logged Or, perhaps, you have a Google Form And that every time you upload a YouTube video, you paste in the ID Or, even better, you could use the YouTube API that keeps track of any time that you upload a new video, and then puts the IDs in the spreadsheets And then you could also use the YouTube API to get the title of the video, as well as how many views it’s gotten All right, and then all it takes is some Apps Script here And then we have example videos that will go into more depth about how this actually works But you’ll see that in just five lines of code inside the function, that’s all it really takes to get all the information And then you just stick it right back into your spreadsheet So let’s talk about some potential use cases that you might want to be doing I’ve alluded to some of them in a business context, but there’s really so much And I think Apps Script is for everyone, whether you want to write a simple script to get the job done once or write something more sustainable that serves an organization OK, and so I’ve talked about some of the business use cases already But in addition to that, perhaps you want to do stuff with calendars and maybe helping people share common resources That’s what the resource management bullet is all about And so you might have a common room at Harvard that you want to allocate to different people And so you could write a script that fairly allocates that Or, maybe people send an email, and say, I want to book this room for a particular time And then Apps Script will take care of it, update it on a spreadsheet or on a calendar, and then give you confirmation email And there’s a lot of automation that can be done with Apps Script So maybe people are emailing in files to a particular Gmail alias And then you are uploading those files from Gmail to Google Drive and keeping an organized file structure of all the permission slips that people are sending in for a field trip And so there’s more that you can do with reporting, so finding data periodically and then compiling beautiful spreadsheets or slide shows with that And then the integration glue bullet– that alludes to how you might be using these third party APIs from Twitter, a Salesforce, or something that I was using the other day was this website called Rebrandly And Rebrandly is really neat in that it allows you to create customized short lengths for your domain And so what I did was I created a Google Form that every time the Google form gets submitted, a certain trigger So on Edit, whenever the spreadsheet tied to Google form– excuse me On Submit, anytime the Google form got submitted, a particular ActionScript got fired And so what I did was I had a form that would let someone specify a long URL and then a short URL And then they could– for my student organization, every time they submit the form the long URL gets rerouted to the short URL using the Rebrandly API So there’s so much you could be doing And I urge you to think about other ways that you might be serving your own organizations that matter in your life Education is also a huge user of G Suite We use it here at Harvard and plenty of other schools use it as well And you might want to create some classroom management tools using Google Apps Script And then a really popular one that a lot of people have been using is called Yet Another Mail Merge or YAMM And this is a way to use a spreadsheet through an add-on So you can go to the top menu and find an add-on and install YAMM or Yet Another Mail Merge And then specify a message and then who you want to be sending it to And then with one run of the script or with the add-on, you can send that customized message to many people in your inbox And this is great if you’re trying to do publicity or otherwise send a customized message to many people And that’s written using Google Apps Script And then you can do other things such as like an out of office calendar for your team at the workplace So just to recap, it’s all just JavaScript So that makes it incredibly easy And it’s done server side So you don’t even have to install anything locally It’s all done in Google’s Cloud It’s different from node.js So that is also server side, but not really what we’re doing here And you don’t learn anything new because it is literally just JavaScript You have access to all those amazing Google technologies that I’ve been talking about, but programmatic access in the way that you can have bulk actions taking place, and things that otherwise would

be impossible, or at least extremely time consuming, such as creating 100 slide decks at once And then you have access to external resources too through third party APIs But everything fells built in just by nature of how the language is structured, which is really neat And you don’t have to worry about deployment, or authentication, or anything like that And there’s so many things you could be doing, such as writing your own scripts, creating add-ons, or building your own web apps as well So consider exploring all of that But what we’re going to do now is we’re going to take a look at a Gmail add-on use case and how you might get started with that So before I actually show the code that goes into a Gmail add-on, because it’s so new, let me show you how a Gmail add-on actually works So I’m going to navigate over to Gmail here And I have this receipt that I’ve gotten from my friend Danny So Danny paid me $8, and I might want to log that into a spreadsheet And so you notice on the right-hand side this is what’s new is that you have access to these little add-ons that you can click on And then you can interact with in various ways So the one that I built right here is called Expense It And it looks like a little receipt So I’m going to click on that, and let’s see what happens So we have this little form that appears And so it says, log your expense It has an expense ID based on how many times I’ve used this already It finds the date of the expense through the email So this email was sent from October 29 And so it finds that How much the expense was– so it reads my message, identifies that it was $8, finds out what the expense was about So this is just based on the subject of the email And then, finally, where the expense should be logged– and that’s just the URL of a spreadsheet And I also have the option of creating a new spreadsheet if I want to So perhaps I went on a business trip over the last weekend, and I want to compile all my expenses from that trip in particular So then I can create a new spreadsheet Maybe I’ll call it weekend expenses So I create the news sheet So this is going to fire off through Google Apps Script And then you’ll see up top in green where it says, it’s created the weekend expenses spreadsheet And now that URL has been replaced down here, and I can submit my expense When I submit my expense– and then I can open the spreadsheet So I’ve logged it successfully Let me actually see that And I’m going to open up the spreadsheet And then there you go Expense number 31 has been logged into this spreadsheet It says that Danny paid me $8 Great I have it there And I can do that with all my emails to get my entire trip summarized in one spreadsheet So that’s the add-on in general And you can imagine a lot of other possibilities with this Perhaps, you might be an airline, and you want to allow users to check into your flight directly from within Gmail So then you can have an add-on that appears on the side And only when you have an email related to that particular airline, you can say check into the flight if it’s 24 hours beforehand And there’s so many other things you could be doing So really consider building this into your own workflow And it might help with your productivity a ton So how do you actually create that? So we go back to Apps Script And so I have the code here already I’ll give you a quick tour of it But there is also a video online on the Google Developers channel where I go into more depth about how you might create this add-on So just to give you a brief overview, we have a few different files here And so they’re dot GS files But it’s still JavaScript It’s just Google Apps Script layered on top of that And so the one that I want to bring your attention to first is this appsscript.json file And so this is called the manifest file And it’s basically where you specify the general metadata that’s associated with this add-on So you specify what scopes you might want to be using And then you also specify this really important part here is what function gets triggered when the add-on gets started And so I have this function called get contextual add-on that’s going to happen when the add-on is first used So I’m going to jump over to get contextual add-on And so that’s this function right here And it’s calling a lot of other functions that I wrote, but you get a sense of the overall gist of what’s going on And what’s happening is that we are customizing what card should be displayed to the user So the card is that UI that you see on the right-hand side And then we’re building that card and returning it so that the user can see it And you can have add-ons that have multiple cards And then you would just return an array of those various cards And then the user can go between the different cards And Google takes care of that UI for you So the general idea is that we’re getting the message And then we’re figuring out what the date was in the message, how much money was on the receipt, as well as what the message was about And then we put all those things together We create the card And then we build it And we send it over so that the user can actually see it So suppose you write all this code And then you can find the actual code on GitHub if you want to try it yourself But how would you actually deploy the add-on to get it working yourself? And so you can publish it to the G Suite Marketplace where someone else from anywhere in the world can install your add-on

That say you just want to test it on your own This is great for a final project If you’re just debugging or you want to make sure things are working on your own machine first, what you can do is you can deploy from Manifest And so that’s just looking at this appsscript.json file, figuring out what it’s all about, and then you can install it directly into your own Gmail And so what you do is you go deploy for Manifest You can create a deployment So we might call this Test Going to save that And then you can get an ID And so you would get this ID And then you would go into Gmail, and then you can go to Settings And then you can copy and paste the ID into the Gmail add-ons part of settings And then you have the add-on appear on the right-hand side in your own emails But if you want to release this more widely, then you have to publish it through the G Suite Marketplace, which is very doable on its own But I’m not going to go into that right now And as a last point, I strongly recommend if you’re interested in making a Gmail add-on that you try going through this example So I’ve created the Code Lab available at g.co/codelabs/gmail-add-ons And so this Code Lab will teach you step by step how you would build that add-on that I just showed you for logging your expenses And so it’ll go through a lot of interesting stuff about Apps Script as well So even if you’re not looking to make a Gmail add-on, I think this is a great way to learn Apps Script You’ll work with spreadsheets You’ll work with what’s called a property store, which allows you to store data in between executions of the script as well So this is a great way to learn about creating a Gmail add-on, any other kind of add-on, or just using Apps Script itself All right, so with that, let’s just wrap up So I’ve already summarize all this So let me just jump through that Cool So how do you keep going from there? So there are a lot of videos and blog posts available online Another really great resource that my mentor created is called the Core Python Programming Blog And he writes out lots of code snippets like you saw at the very beginning with the YouTube or the Slides API that explain how you can be using the APIs through Python But if you want to be using something else like Java, you can also look at those examples and then extend it into your own language And so that’s a great way to look at the APIs But then you can also look at Apps Script on the developers.google website And we have a lot of videos as well If you just search for the G Suite Dev Show on YouTube, you’ll find a ton of really great videos that talk about different code examples in-depth for five or six minutes Try out the Code Lab In addition to the Gmal Add-Ons Code Lab, there’s also a code lab in the Sheets API as well as the Slides API And both of those I believe are written using Node So if you are a Node or JavaScript person, that’s a great place to turn to And then there a lot of documentation available as well So take a look at that website But then also feel free to turn to Stack Overflow And we also have a Google page where you can check out the community and ask questions there So I hope that helps And I’ll leave it at that If you have any questions in the audience, feel free to ask me now And anything online, just leave a note on YouTube So thanks for tuning in These slides are available online And I hope you’ve learned something that you can use in real life Thanks