> ## Documentation Index
> Fetch the complete documentation index at: https://www.octoparse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# APIキーを取得してログイン

> OAuthまたはAPIキーでOctoparse CLIを認証します。CIや自動化環境では環境変数またはstdinを使用します。

## 認証要件

ほとんどのOctoparse CLIコマンドには認証が必要です。APIキーまたはOAuthセッションが、アカウントの識別とタスク・データへのアクセス認可に使用されます。

<Warning>
  ローカルの `--task-file` や `.otd` の実行を含め、すべての機能コマンドには有効な認証情報が必要です。タスクの一覧表示、実行、エクスポートを行う前に認証してください。
</Warning>

認証なしで実行できるのは、セットアップおよび診断コマンドのみです。

```bash theme={null}
octoparse --help
octoparse --version
octoparse capabilities
octoparse doctor
octoparse browser doctor
octoparse auth
octoparse auth info
```

## ログイン方法

Octoparse CLIはOAuthとAPIキーの2種類のログイン方法をサポートしています。

### OAuth（ブラウザ認証）

ブラウザでログインし、アクセストークンとリフレッシュトークンをローカルに保存します。

```bash theme={null}
octoparse auth login --oauth
```

APIキーを手動で管理したくない場合や、チームがSSOを使用している場合に適しています。

### APIキー

Octoparseコンソールでキーを作成します。

<Card title="API keysページを開く" icon="key" href="https://www.octoparse.com/console/account-center/api-keys">
  アカウントセンターでOctoparse APIキーを作成、コピー、管理します。
</Card>

**対話形式でログイン** — APIキーページを開き、キーの貼り付けを促します。

```bash theme={null}
octoparse auth login
```

**コピーしたキーで直接ログイン** — キーを検証してすぐに保存します。

```bash theme={null}
octoparse auth login <apiKey>
```

**ブラウザを開かない：**

```bash theme={null}
octoparse auth login --no-open
```

**stdinからキーを読み取る** — シークレットマネージャーやCIパイプライン向け：

```bash theme={null}
echo "<apiKey>" | octoparse auth login --stdin
```

1Password CLIの例：

```bash theme={null}
op read "op://vault/octoparse/credential" | octoparse auth login --stdin
```

<Note>
  CLIはAPIキーを保存前に検証します。無効なキーは保存されません。
</Note>

## 環境変数を使用する

CIや一時的なセッションでは、保存された認証情報の代わりに環境変数で認証情報を渡します。

```bash theme={null}
OCTO_ENGINE_API_KEY=xxx octoparse task list --json
```

ベアラートークンでのアクセス（短期間のCIジョブに便利）：

```bash theme={null}
OCTO_ENGINE_ACCESS_TOKEN=xxx octoparse task list --json
```

APIのベースURLも上書きできます。

```bash theme={null}
OCTO_ENGINE_API_BASE_URL=https://example.com OCTO_ENGINE_API_KEY=xxx octoparse task list
```

## 認証情報の優先順位

Octoparse CLIは次の順序で認証情報を確認します。

```text theme={null}
1. OCTO_ENGINE_ACCESS_TOKEN  （ベアラートークン、最優先）
2. OCTO_ENGINE_API_KEY       （APIキーによる上書き）
3. ~/.octoparse/credentials.json  （auth loginで保存済み）
```

認証情報ファイルは `octoparse auth login` によって自動的に作成されます。

macOSとLinux：

```text theme={null}
~/.octoparse/credentials.json
```

Windows：

```text theme={null}
%USERPROFILE%\.octoparse\credentials.json
```

<Warning>
  APIキーやトークンをGit、スクリプト、ドキュメント、スクリーンショット、共有ログ、CI出力に含めないでください。
</Warning>

## 認証状態を確認・管理する

セッションが有効かどうかを確認します。

```bash theme={null}
octoparse auth status
```

アカウントと認証情報の詳細を表示します。

```bash theme={null}
octoparse auth info
```

保存された認証情報を削除します。

```bash theme={null}
octoparse auth logout
```

## 次のステップ

<CardGroup cols={2}>
  <Card title="最初のタスクを実行する" href="run-your-first-task">
    タスクを一覧表示し、確認し、ローカルで実行し、データをエクスポートします。
  </Card>

  <Card title="すべてのコマンドを見る" href="../reference/command-cheatsheet">
    認証、タスク、ローカル実行、クラウド実行、エクスポート関連のコマンドを確認します。
  </Card>
</CardGroup>
