smithery.ai

google-drive-go

Expert guidance for using the Google Drive API with Go, including OAuth2 authentication, file operations (list, upload, download, search), folder management, permissions, and best practices.

First seen Apr 18, 2026

Installation

$ npx skills add https://smithery.ai

Summary

  • Expert guidance for using the Google Drive API with Go, including OAuth2 authentication, file operations (list, upload, download, search), folder management, permissions, and best practices.
  • Use when building Go applications that interact with Google Drive, implementing file storage/sync features, managing Drive permissions, or any Google Drive integration tasks in Go.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery.ai · top by installs.

npx skills add https://smithery.ai

Browse all from smithery.ai

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 6,309 B
  • docs SUMMARY.md 394 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 1 installs

SKILL.md

Google Drive Go API

This skill provides guidance for working with Google Drive API v3 in Go applications.

Quick Start

1. Setup Authentication

Google Drive API uses OAuth2 for authentication. Set up credentials:

import (
    "context"
    "golang.org/x/oauth2/google"
    "google.golang.org/api/drive/v3"
    "google.golang.org/api/option"
)

// Read credentials from JSON file (from Google Cloud Console)
b, err := os.ReadFile("credentials.json")
if err != nil {
    log.Fatalf("Unable to read client secret file: %v", err)
}

// Configure OAuth2 with required scopes
config, err := google.ConfigFromJSON(b, drive.DriveScope)
if err != nil {
    log.Fatalf("Unable to parse client secret file: %v", err)
}

// Get authenticated client
client := getClient(config)

// Create Drive service
srv, err := drive.NewService(ctx, option.WithHTTPClient(client))

2. Common OAuth2 Scopes

  • drive.DriveScope - Full access to Drive
  • drive.DriveFileScope - Access to files created by the app
  • drive.DriveMetadataReadonlyScope - Read-only metadata access
  • drive.DriveReadonlyScope - Read-only access

3. Authentication Helper Functions

See references/auth.md for complete OAuth2 implementation including token storage and retrieval.

Common Operations

List Files

r, err := srv.Files.List().
    PageSize(10).
    Fields("nextPageToken, files(id, name, mimeType, size)").
    Do()
if err != nil {
    log.Fatalf("Unable to retrieve files: %v", err)
}

for _, file := range r.Files {
    fmt.Printf("%s (%s)\n", file.Name, file.Id)
}

Upload File

file := &drive.File{
    Name: "myfile.txt",
    MimeType: "text/plain",
}

content, err := os.Open("local-file.txt")
if err != nil {
    log.Fatalf("Unable to read file: %v", err)
}
defer content.Close()

createdFile, err := srv.Files.Create(file).Media(content).Do()
if err != nil {
    log.Fatalf("Unable to create file: %v", err)
}
fmt.Printf("File ID: %s\n", createdFile.Id)

Download File

// Get file metadata
file, err := srv.Files.Get(fileId).Do()

// Download content
resp, err := srv.Files.Get(fileId).Download()
if err != nil {
    log.Fatalf("Unable to download file: %v", err)
}
defer resp.Body.Close()

// Save to local file
out, err := os.Create(file.Name)
if err != nil {
    log.Fatalf("Unable to create local file: %v", err)
}
defer out.Close()

io.Copy(out, resp.Body)

Search Files

query := "name contains 'report' and mimeType='application/pdf'"
r, err := srv.Files.List().
    Q(query).
    Fields("files(id, name, createdTime)").
    Do()

Common query patterns:

  • name = 'filename.txt' - Exact name match
  • name contains 'keyword' - Partial match
  • mimeType = 'application/pdf' - Filter by type
  • 'parent-folder-id' in parents - Files in folder
  • trashed = false - Exclude trashed files

Create Folder

folder := &drive.File{
    Name:     "My Folder",
    MimeType: "application/vnd.google-apps.folder",
}

createdFolder, err := srv.Files.Create(folder).Do()
if err != nil {
    log.Fatalf("Unable to create folder: %v", err)
}

Manage Permissions

permission := &drive.Permission{
    Type: "user",
    Role: "writer",
    EmailAddress: "[email protected]",
}

_, err := srv.Permissions.Create(fileId, permission).Do()
if err != nil {
    log.Fatalf("Unable to share file: %v", err)
}

Permission roles: owner, organizer, fileOrganizer, writer, commenter, reader

Advanced Topics

Pagination

Handle large result sets with pagination:

pageToken := ""
for {
    r, err := srv.Files.List().
        PageSize(100).
        PageToken(pageToken).
        Fields("nextPageToken, files(id, name)").
        Do()
    if err != nil {
        log.Fatalf("Error: %v", err)
    }
    
    for _, file := range r.Files {
        // Process file
    }
    
    pageToken = r.NextPageToken
    if pageToken == "" {
        break
    }
}

File Metadata Fields

Use the Fields parameter to specify which fields to return:

Fields("files(id, name, mimeType, size, createdTime, modifiedTime, webViewLink)")

Common fields: id, name, mimeType, size, createdTime, modifiedTime, parents, webViewLink, iconLink, thumbnailLink

Export Google Docs

Export Google Workspace files to different formats:

// Export Google Doc as PDF
resp, err := srv.Files.Export(fileId, "application/pdf").Download()

// Export Google Sheet as Excel
resp, err := srv.Files.Export(fileId, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").Download()

Best Practices

  1. Use appropriate scopes - Request minimum necessary permissions
  2. Handle rate limits - Implement exponential backoff for retries
  3. Batch operations - Use batch requests for multiple operations
  4. Cache tokens - Store OAuth2 tokens to avoid repeated authorization
  5. Use fields parameter - Only request needed fields to reduce bandwidth
  6. Handle pagination - Always implement pagination for list operations
  7. Check mime types - Validate file types before operations
  8. Error handling - Properly handle API errors and network issues

Common MIME Types

  • Plain text: text/plain
  • PDF: application/pdf
  • JPEG: image/jpeg
  • PNG: image/png
  • Google Docs: application/vnd.google-apps.document
  • Google Sheets: application/vnd.google-apps.spreadsheet
  • Google Slides: application/vnd.google-apps.presentation
  • Folder: application/vnd.google-apps.folder

Resources

Installation

go get google.golang.org/api/drive/v3
go get golang.org/x/oauth2/google