• #gogcli
  • #google-workspace
  • #cli
  • #windows
開発未分類メモ

gogcli セットアップガイド(Windows版)

gogcliは、Google Workspaceの各種サービス(Gmail、Calendar、Drive、Sheets等)をコマンドラインから操作できるCLIツールです。

前提条件

  • Windows 10/11
  • インターネット接続
  • Googleアカウント
  • Google Cloudプロジェクト(作成方法は後述)

Step 1: Goのインストール

  1. https://go.dev/dl/ にアクセス
  2. 「Microsoft Windows」go1.xx.x.windows-amd64.msi をダウンロード
  3. インストーラーを実行(デフォルト設定でOK)

確認方法: PowerShellを新しく開いて以下を実行:

go version

go version go1.24.x windows/amd64 のように表示されればOK


Step 2: Gitのインストール

すでにインストール済みならスキップ。

  1. https://git-scm.com/download/win にアクセス
  2. インストーラーをダウンロードして実行(デフォルト設定でOK)

確認方法:

git --version

Step 3: ソースコードのダウンロード

PowerShellで以下を実行:

cd ~
git clone https://github.com/steipete/gogcli.git
cd gogcli

Step 4: ビルド

go build -o gog.exe ./cmd/gog

数秒〜数十秒待つと、gogcli フォルダ内に gog.exe ができます。

確認方法:

.\gog.exe --help

Step 5: PATHに追加

どこからでも gog コマンドを使えるようにします。

# binフォルダ作成
mkdir $env:USERPROFILE\bin -Force

# gog.exeをコピー
copy gog.exe $env:USERPROFILE\bin\

# PATHに追加
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$env:USERPROFILE\bin", "User")

重要: PowerShellを一度閉じて、新しく開き直してください。

確認方法:

gog --help

Step 6: Google Cloud OAuthクライアントの作成

  1. プロジェクト作成: https://console.cloud.google.com/projectcreate
  2. OAuth同意画面の設定: https://console.cloud.google.com/auth/branding
    • アプリ名などを設定
  3. テストユーザーの追加: https://console.cloud.google.com/auth/audience
    • 自分のGoogleアカウントを追加
  4. OAuthクライアントの作成: https://console.cloud.google.com/auth/clients
    • 「認証情報を作成」→「OAuthクライアントID」
    • アプリケーションの種類:デスクトップアプリ
    • 作成後、JSONファイルをダウンロード

Step 7: gogcliに認証情報を登録

ダウンロードしたJSONファイルを登録します。

gog auth credentials $env:USERPROFILE\Downloads\client_secret_xxxxx.json

注意: gogcliは ~ をホームディレクトリとして展開しません。$env:USERPROFILE またはフルパスを使ってください。

認証情報の保存先:

C:\Users\<ユーザー名>\AppData\Roaming\gogcli\credentials.json

登録後、ダウンロードフォルダの元ファイルは削除してOKです(セキュリティのため推奨)。


Step 8: Googleアカウント認証

gog auth add [email protected]
  1. ブラウザが自動で開く
  2. Googleアカウントでログイン
  3. 権限を許可
  4. 「Authorization received. Finishing…」と表示されれば成功

Step 9: APIの有効化

重要: Google CloudプロジェクトでAPIを有効化しないと、各サービスは使えません。

以下のリンクから必要なAPIを有効化してください(プロジェクトIDは適宜変更):

主要API

サービス有効化リンク
Gmail APIhttps://console.cloud.google.com/apis/api/gmail.googleapis.com?project=560857707782
Google Calendar APIhttps://console.cloud.google.com/apis/api/calendar-json.googleapis.com?project=560857707782
Google Drive APIhttps://console.cloud.google.com/apis/api/drive.googleapis.com?project=560857707782
Google Sheets APIhttps://console.cloud.google.com/apis/api/sheets.googleapis.com?project=560857707782
Google Docs APIhttps://console.cloud.google.com/apis/api/docs.googleapis.com?project=560857707782
Google Slides APIhttps://console.cloud.google.com/apis/api/slides.googleapis.com?project=560857707782
People API(連絡先)https://console.cloud.google.com/apis/api/people.googleapis.com?project=560857707782
Tasks APIhttps://console.cloud.google.com/apis/api/tasks.googleapis.com?project=560857707782

追加API(Workspace向け)

サービス有効化リンク
Google Chat APIhttps://console.cloud.google.com/apis/api/chat.googleapis.com?project=560857707782
Google Classroom APIhttps://console.cloud.google.com/apis/api/classroom.googleapis.com?project=560857707782
Google Keep APIhttps://console.cloud.google.com/apis/api/keep.googleapis.com?project=560857707782
Cloud Identity API(Groups)https://console.cloud.google.com/apis/api/cloudidentity.googleapis.com?project=560857707782

注意: 有効化後、反映まで数分かかることがあります。


本家にない機能を追加する(Fork + Upstream運用)

gogcliはOSSなので、本家にまだない機能を自分で追加して使える。本家が対応したら、そちらに追従すればよい。

最初のクローン時にやること

普通に git clone した状態では、origin が本家のリポジトリを指している。自分の変更を管理するために、本家を upstream として登録する。

cd ~/gogcli

# 現在のリモートを確認
git remote -v
# → origin  https://github.com/steipete/gogcli.git (fetch)

# 本家を upstream として登録
git remote rename origin upstream

# 自分のGitHubにフォークを作っている場合は origin を設定
# git remote add origin https://github.com/自分のアカウント/gogcli.git

GitHubにフォークを作らない場合(ローカルだけで管理する場合)は、upstream だけでOK。

機能追加の手順

# 本家の最新を取得
git fetch upstream

# 機能追加用ブランチを作成
git checkout -b feat/chat-delete upstream/main

# コード変更...

# コミット
git add .
git commit -m "feat: add chat messages delete command"

# ビルド
go build -o gog.exe ./cmd/gog
copy gog.exe $env:USERPROFILE\bin\

本家が同じ機能を実装したら

# 本家の最新を取得
git fetch upstream

# mainブランチに切り替え
git checkout main

# 本家の変更を取り込む
git merge upstream/main

# 再ビルド
go build -o gog.exe ./cmd/gog
copy gog.exe $env:USERPROFILE\bin\

自分のブランチはもう不要なので削除できる:

git branch -d feat/chat-delete

コンフリクトが発生した場合は、本家の実装を優先して解消すればよい。

実例:Chat messages delete の追加

2026-01-30時点で、gogcli本家にはChat messagesのdelete機能がない。以下のファイルを変更して追加した:

  • internal/cmd/chat_messages.go - ChatMessagesDeleteCmd 構造体と Run メソッドを追加
  • internal/cmd/chat_helpers.go - normalizeMessage ヘルパー関数を追加

使い方:

# メッセージ一覧からリソース名を取得(新しい順)
gog chat messages list spaces/AAAA9qhlGLw --max 10 --order "createTime desc" --account [email protected]

# メッセージを削除(リソース名を指定)
gog chat messages delete spaces/AAAA9qhlGLw/messages/<messageId> --account [email protected]

# 確認なしで削除
gog chat messages delete spaces/AAAA9qhlGLw/messages/<messageId> --account [email protected] --force

動作確認結果(2026-01-30)

「面談スケジュール自動登録」のテストメッセージ2件を削除して動作を確認した。

# 最新メッセージを確認
gog chat messages list spaces/AAAA9qhlGLw --max 5 --order "createTime desc" --account [email protected]

# 2件削除
gog chat messages delete "spaces/AAAA9qhlGLw/messages/cuEBh5O6sC4.cuEBh5O6sC4" --account [email protected] --force
gog chat messages delete "spaces/AAAA9qhlGLw/messages/pE96SwiAIbw.pE96SwiAIbw" --account [email protected] --force

Google Chat上で「メッセージは投稿者によって削除されました(アプリ経由)」と表示され、正常に削除されたことを確認。


使用例

# カレンダー一覧
gog calendar list

# 今週の予定
gog calendar events primary --from 2025-01-30T00:00:00+09:00 --to 2025-02-06T00:00:00+09:00

# メール検索(過去7日)
gog gmail search 'newer_than:7d' --max 10

# Driveファイル一覧
gog drive ls --max 20

# JSON出力(スクリプト連携用)
gog --json calendar events primary

トラブルシューティング

「accessNotConfigured」エラー

Google API error (403 accessNotConfigured): Google Calendar API has not been used in project...

原因: Google CloudプロジェクトでAPIが有効化されていない

対処: エラーメッセージに表示されるURLにアクセスして「有効にする」をクリック


~ が展開されない

open ~\Downloads\...: The system cannot find the path specified.

原因: gogcliは ~ をホームディレクトリとして展開しない

対処: $env:USERPROFILE またはフルパスを使用

# NG
gog auth credentials ~\Downloads\file.json

# OK
gog auth credentials $env:USERPROFILE\Downloads\file.json
gog auth credentials "C:\Users\numbe\Downloads\file.json"

keyringバックエンドの不一致でトークンが見つからない

token source: get token for [email protected]: read token: open C:\Users\...\keyring\token:default:[email protected]: The filename, directory name, or volume label syntax is incorrect.

原因: OAuthトークンをWindows Credential Manager(auto/keychainバックエンド)に保存したが、config.jsonkeyring_backendfile に変わっている。file バックエンドはファイル名にコロンを使うため、Windowsでパスが不正になる。

対処: keyringバックエンドを auto に戻す。

gog auth keyring auto
gog auth list   # アカウントが表示されればOK

確認方法:

gog auth keyring
# → keyring_backend: auto, source: config と表示される

補足: ビルドし直しても認証トークンは消えない。トークンはWindows Credential Managerに保存されており、バイナリとは独立している。


SmartScreen警告(署名なしexe)

GitHubリリースからダウンロードしたexeは、コード署名がないためSmartScreen警告が出ます。

対処:

  • 「詳細情報」→「実行」で続行
  • または、この手順のようにソースからビルドする

設定ファイルの場所

C:\Users\<ユーザー名>\AppData\Roaming\gogcli\
├── config.json       # 設定
└── credentials.json  # OAuth認証情報

参考リンク