Google Cloud for Student Developers: Accessing G Suite REST APIs
Recently, we introduced the “Google Cloud for Student Developers” video series to encourage students majoring in STEM fields to gain development experience using industry APIs (application programming interfaces) for career readiness. That first episode provided an overview of the G Suite developer landscape while this episode dives deeper, introducing G Suite’s HTTP-based RESTful APIs, starting with Google Drive.
The first code sample has a corresponding codelab (a self-paced, hands-on tutorial) where you can build a simple Python script that displays the first 100 files or folders in your Google Drive. The codelab helps student (and professional) developers…
- Realize it is something that they can accomplish
- Learn how to create this solution without many lines of code
- See what’s possible with Google Cloud APIs
While everyone is familiar with using Google Drive and its web interface, many more doors are opened when you can code Google Drive. Check this blog post and video for a more comprehensive code walkthrough as well as access the code at its open source repository. What may surprise readers is that the entire app can be boiled down to just these 3-4 lines of code (everything else is either boilerplate or security):
DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))
files = DRIVE.files().list().execute().get('files', )
for f in files:
Once an “API service endpoint” to Google Drive is successfully created, calling the
list() method in Drive’s
files() collection is all that’s needed. By default,
files().list() returns the first 100 files/folders—you can set the
pageSize parameter for a different amount returned.
The video provides additional ideas of what else is possible by showing you examples of using the Google Docs, Sheets, and Slides APIs, and those APIs will be accessed in a way similar to what you saw for Drive earlier. You’ll also hear about what resources are available for each API, such as documentation, code samples, and links to support pages.
If you wish to further explore coding with G Suite REST APIs, check out some additional videos for the Drive, Sheets, Gmail, Calendar, and Slides APIs. Stay tuned for the next episode which highlights the higher-level Google Apps Script developer platform.
We look forward to seeing what you build with Google Cloud!