Skip to content

Instantly share code, notes, and snippets.

@alileza
Created April 9, 2026 12:07
Show Gist options
  • Select an option

  • Save alileza/9f079dd5268c5b3c29a1f5dfb4ac0951 to your computer and use it in GitHub Desktop.

Select an option

Save alileza/9f079dd5268c5b3c29a1f5dfb4ac0951 to your computer and use it in GitHub Desktop.

List Google Drive Files Using Google Workspace CLI

Prerequisites

  • Node.js installed
  • A Google Cloud project

Step 1: Install Google Workspace CLI

npm install -g @googleworkspace/cli

Verify:

gws --version

Step 2: Create OAuth Credentials in Google Cloud Console

  1. Go to Google Cloud Console
  2. Select or create a project
  3. Navigate to APIs & Services → OAuth consent screen
  4. Set up the consent screen:
    • User type: External
    • Fill in the required fields (app name, support email)
    • Add your Google account as a test user
    • Save
  5. Navigate to APIs & Services → Credentials
  6. Click + Create Credentials → OAuth client ID
  7. Application type: Desktop app
  8. Click Create and Download JSON

Step 3: Enable Google Drive API

  1. Go to APIs & Services → Library
  2. Search for Google Drive API
  3. Click Enable

Step 4: Configure the CLI

Copy the downloaded client secret JSON to the gws config directory:

mkdir -p ~/.config/gws
cp ~/Downloads/client_secret_*.json ~/.config/gws/client_secret.json

Step 5: Authenticate

gws auth login

This opens a browser window. Sign in with the Google account you added as a test user.

Step 6: List Your Drive Files

# List first 10 files
gws drive files list --params '{"pageSize": 10}'

# List all files
gws drive files list --params '{"pageSize": 50}' --page-all

Useful Commands

# Search for files by name
gws drive files list --params '{"q": "name contains '\''budget'\''", "pageSize": 10}'

# List only spreadsheets
gws drive files list --params '{"q": "mimeType = '\''application/vnd.google-apps.spreadsheet'\''", "pageSize": 10}'

# List files in a specific folder
gws drive files list --params '{"q": "'\''FOLDER_ID'\'' in parents", "pageSize": 10}'

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment