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

# Google Drive

> サービスアカウントを用いたGoogle Driveとの連携手順です。

## サポートする機能

<Badge color="blue">ファイル集計</Badge> <Badge color="blue">ファイル権限管理</Badge>

## Google Driveとの連携

Google Driveとの連携手順です。連携することで公開されているファイルの情報を取得します。（[外部共有コンテンツ管理機能について](/it-management/file-management/aakpi1r7gq-file-management#1023961436)）

<Info>
  * アカウント情報は取得いたしません。
  * 共有ドライブ（マイドライブ含む）に公開（共有）されているファイル名とそのリンクを取得いたします。データはAdminaに同期しません。
  * ファイルの閲覧には、AdminaのAdminロールが必要です。Adminaのロールについては次のページをご覧ください。
</Info>

[Adminaの管理ユーザについて：ロールの違いを教えてください。](/it-management/settings/yne7fl2lcy-role-new)

## 事前準備

### APIの有効化（Google Cloud Platform）

1. Google Cloud Platformから連携用のアカウントを作成します。[Google Cloud Console](https://console.cloud.google.com/) にアクセスし、任意のプロジェクトを選択 or 新規作成します。

2. **API とサービス** > 有効化済みの **API** で、次の2つのAPIが有効になっていることを確認します。 有効になっていない場合、[API Library](https://console.cloud.google.com/apis/library)の一覧から追加します。
   * **Google Drive API**
   * **Admin SDK API**

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681952321507.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=7a1188f2231eab92f37f2c489b3a918f" alt="APIの有効化" width="2520" height="1188" data-path="images/integrations/k7vonejs7q/1681952321507.png" />

### 連携用アカウントの作成

3. **API とサービス > 認証情報 > 認証情報を作成 > サービスアカウント**に移動します。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681952435408.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=3204f574341c8969818832bc9966fc4e" alt="サービスアカウント作成" width="2648" height="830" data-path="images/integrations/k7vonejs7q/1681952435408.png" />

4. サービスアカウント名に任意の名前を入力し、\[**完了**] をクリックします（step2,3は不要です）

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681952609494.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=a39947a153311d4d4d5b6a5ef56e2b8a" alt="サービスアカウント名入力" width="2102" height="1206" data-path="images/integrations/k7vonejs7q/1681952609494.png" />

### APIキーの発行

5. **API と サービス > 認証情報** に作成したサービスアカウントが表示されますのでクリックします。

6. \[**キー**] タブに移動し、**鍵を追加 > 新しい鍵を作成** をクリックします。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681953025811.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=177e90df194ce1cd2fd0770304f5c0a4" alt="鍵の作成" width="2682" height="1092" data-path="images/integrations/k7vonejs7q/1681953025811.png" />

7. **JSON**を選択し、\[作成] ボタンをクリックします。「秘密鍵がパソコンに保存されました」と表示され、JSONファイルが自動的にダウンロードされます。Client IDなど、Adminaとの連携に必要なパラメータが登録されているため、保管しておきます。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681953121670.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=9e97d2f526f4c6e98f60b87e90b0fcda" alt="JSON形式で保存" width="1086" height="678" data-path="images/integrations/k7vonejs7q/1681953121670.png" />

### ドメイン全体の委任の設定（Google Adminコンソール）

8. Google Workspaceの [Admin console](https://admin.google.com/)に移動し、 **セキュリティ > APIの制御 > \[ドメイン全体の委任を管理]** をクリックします。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1676945315793.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=43495b4ece5251bf6b960bb49a659254" alt="ドメイン全体の委任" width="3002" height="1432" data-path="images/integrations/k7vonejs7q/1676945315793.png" />

9. \[**新しく追加**]ボタンをクリックします.

10. 保存しておいたJSONファイルを開きます。**Client ID** に、Jsonファイル内にある`client_id` の値を入力します。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681953322629.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=184e0ace6299ba27531eb70578918240" alt="Client ID入力" width="3062" height="1246" data-path="images/integrations/k7vonejs7q/1681953322629.png" />

11. **OAuth スコープ**に以下の4つの値を入力し、\*\*\[承認]\*\*をクリックします
    1. `https://www.googleapis.com/auth/drive`
    2. `https://www.googleapis.com/auth/admin.directory.user.readonly`
    3. `https://www.googleapis.com/auth/admin.directory.group.readonly`
    4. `https://www.googleapis.com/auth/admin.directory.domain.readonly`

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1676947283032.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=86ac2a9aea919857496c7e479b72aa92" alt="OAuthスコープ設定" width="920" height="806" data-path="images/integrations/k7vonejs7q/1676947283032.png" />

<Info>
  a.のスコープを`https://www.googleapis.com/auth/drive.readonly`と設定もできます。
  この場合、すべてRead Onlyで連携することが可能になりますが、「マイドライブ」のみの取得（共有ドライブのファイルは取得不可）となります。
</Info>

## インテグレーションのセットアップ

1. Adminaのインテグレーション画面にて、**Google Drive**で検索します。

2. 保存しておいたJSONファイルを開きます。以下の値をそれぞれ入力し、\[**連携する**]をクリックします。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681953436548.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=fccd702b09cfbae1f3552450c38aece9" alt="連携設定画面" width="3060" height="1230" data-path="images/integrations/k7vonejs7q/1681953436548.png" />

3. サービスアカウントのメールアドレス：JSONファイル内の`client_email` の値を入力します。

4. 秘密鍵：JSONファイル内の秘密鍵`private_key`を入力します。
   **-----BEGIN PRIVATE KEY-----** から **-----END PRIVATE KEY-----** までを入力ください。（先頭の `"` やおよび最後の`\n",`は不要です。）

5. **メールアドレス：** **Google Workspace** の特権管理者のメールアドレスを入力ください。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1683722820125.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=d812d4ecfd62a8f8c7f9ffcfa5167e72" alt="認証情報入力" width="482" height="745" data-path="images/integrations/k7vonejs7q/1683722820125.png" />

<Info>
  信頼ドメイン：指定したドメインを、外部公開ファイルの検知から除外できます。グループ会社のドメインなど、外部として検知させたくない場合に指定します。複数存在する場合、次のように , (カンマ）で区切って入力ください。（自社ドメインの入力は不要です）
  `moneyfoward.co.jp, i.moneyfoward.com`
</Info>

6. Google Drive との連携に成功すると、サービス >「ファイル」タブが表示され、共有されているファイルの情報が表示されます。（同期完了までにはファイル数によって時間がかかります。）

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1673406422261.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=1de8d86c78a48b90400b5154a0728471" alt="連携成功画面" width="3018" height="1494" data-path="images/integrations/k7vonejs7q/1673406422261.png" />

正常に完了しない場合は、インテグレーション画面のステータスタブから**編集**し、再度連携をお試しください。

解決しない場合はチャットにてお問い合わせください。

Google Driveの連携概要については[連携ページ](https://admina.moneyforward.com/jp/integrations/google-drive)をご覧ください。

## 共有の停止

取得した共有ファイルのステータスを確認し、共有を停止できます。

右端の引き出しから、\[共有]ボタンをクリックします。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681981353191.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=287e23b60306dc0eaf4fd99545830a43" alt="共有ボタン" width="2794" height="1622" data-path="images/integrations/k7vonejs7q/1681981353191.png" />

共有を停止したいユーザー・グループ・リンクを選択し、\[適用]をクリックします。

<img src="https://mintcdn.com/moneyforwardi/H1U6E2frRcGDFDpD/images/integrations/k7vonejs7q/1681981480764.png?fit=max&auto=format&n=H1U6E2frRcGDFDpD&q=85&s=d2f26535cbab94e990e97768b39cf8ac" alt="共有停止" width="1978" height="1262" data-path="images/integrations/k7vonejs7q/1681981480764.png" />

## FAQ

### Q. 各ファイルの公開ステータスについて教えてください。

A. 以下をご参照ください。

| ステータス    | 説明                                                              |
| -------- | --------------------------------------------------------------- |
| **外部公開** | Google Workspaceに登録されているドメイン以外のアドレスに共有されているファイルを「外部共有」と判定しています。 |
| **全体公開** | 「リンクを知っている全員」に公開されているファイルを「全体公開」として表示します。                       |
