This codelab introduces developers to Google Workspace (formerly G Suite) APIs (Gmail, Google Drive, Calendar, Sheets, Slides, etc.) by writing a simple Python script that lists the first 100 files/folders in a user's Google Drive. Access it at http://g.co/codelabs/gsuite-apis-intro.
- A Google account (Google Workspace accounts may require administrator approval)
- Familiarity with shell commands on POSIX-compliant systems (Linux, Mac OS X); Windows users also welcome
- Ability to create source files with either a code editor or shell commands.
- Basic skills in Python (2 or 3), but you use any supported language
- Some files and/or folders in your Google Drive
This repo is part of the codelab introducing developers to using Google Workspace (REST/HTTP) APIs. The example will be done in Python for brevity and wide availability, but all common languages are supported. The tutorial shows how to use the developer console to create and manage projects, including obtaining the credentials needed in your apps, then moves on to the primary code sample that displays the first 100 files & folders in your Google Drive by using the Drive API.
oauth2client
library deprecated:
The oauth2client
library was deprecated in 2017 in favor of newer replacements. However the newer libraries do not yet support either user authorization nor user credentials storage, two features that are required in this codelab. When those features become available, we will migrate to the newer libraries. For now, oauth2client
still works, even in maintenance mode, and provides automated, threadsafe, and 2.x/3.x-compatible storage of and access to OAuth2 tokens for users whereas the newer libraries do not (yet).
Use of the Google Drive API (and most Google Workspace APIs) are covered by a monthly subscription fee, including the free consumer Google/Gmail accounts (monthly fee of $0USD), meaning you can use the APIs as long as you stay within each API's daily/monthly limits. Exceeding the limits will result in failed requests/exceptions. Some APIs have a support page to request additional quota.
Filename | Description |
---|---|
drive_list.py |
The original sample app as featured in codelab |
drive_list-new.py |
Same as drive_list.py but uses newer auth libraries (not threadsafe nor easily Python 2-3 compatible nor handles auth tokens [extra JSON storage code]) |
- Codelab to build code sample
- Code deep dive blogpost
- Code deep dive video
- Google Drive API home page
- Other Google Drive API videos
- Google Workspace REST APIs intro video
- Google Workspace REST APIs "world tour" video
- Drive Service on Apps Script
- Advanced Drive Service on Apps Script
- Google Workspace developers home page
- Stack Overflow
If you've found an error in the codelab or the sample app, check the Issues tab to see if there's an open issue or file a new one. Patches are encouraged; please refer to CONTRIBUTING for details.