Complete the steps described in the rest of this page to create a simple Gocommand-line application that makes requests to the Drive API.
Create and edit web-based documents, spreadsheets, and presentations. Store documents online and access them from any computer.
Prerequisites
Google Photos is the home for all your photos and videos, automatically organized and easy to share. Get Google Photos Go to Google Photos. The home for your memories. Go to Google Photos. Get Google Photos. Your memories across devices. Securely back-up your photos and videos to Google Photos and enjoy them from any device. With a Google Account, you get 15 GB of storage for free. Storage gets used by Google Drive, Gmail, and Google Photos, so you can store files, save your email attachments, and back up photos. Access Google Hangouts with a free Google account (for personal use) or Google Workspace account (for business use). Sign in - Google Accounts.
To run this quickstart, you need the following prerequisites:
- Go, latest version recommended.
- Git, latest version recommended.
- A Google account with Google Drive enabled
Step 1: Turn on the Drive API
Click this button to create a new Cloud Platform project and automaticallyenable the Drive API:
In resulting dialog click DOWNLOAD CLIENT CONFIGURATION and save the filecredentials.json
to your working directory.Step 2: Prepare the workspace
- Set the
GOPATH
environment variable to your working directory. - Get the Drive API Go client library and OAuth2 packageusing the following commands:
Step 3: Set up the sample
Create a file named
quickstart.go
in your working directory and copyin the following code:Step 4: Run the sample
Build and run the sample using the following command from your workingdirectory:
The first time you run the sample, it will prompt you to authorize access:
- Browse to the provided URL in your web browser.If you are not already logged into your Google account, you will beprompted to log in. If you are logged into multiple Google accounts, youwill be asked to select one account to use for the authorization.
- Click the Accept button.
- Copy the code you're given, paste it into the command-line prompt, and pressEnter.
Notes
- Authorization information is stored on the file system, so subsequentexecutions will not prompt for authorization.
- The authorization flow in this example is designed for a command-lineapplication. For information on how to perform authorization in a webapplication, seeUsing OAuth 2.0 for Web Server Applications.
How To Google Drive
Further reading
Go To Google Drive
Troubleshooting
This section describes some common issues that you may encounter whileattempting to run this quickstart and suggests possible solutions.
Go To Google Drive Sign In
This app isn't verified.
Go To Google Drive Train
The OAuth consent screen that is presented to the user may show the warning'This app isn't verified' if it is requesting scopes that provide access tosensitive user data. These applications must eventually go through theverification process toremove that warning and other limitations. During the development phase you cancontinue past this warning by clickingAdvanced > Go to {Project Name} (unsafe).