# Google Business Profile Import Integration Using The CLI

Google Business Profile(旧Google My Business)インポート統合を使用して、顧客情報をインポートできます。このコネクタを使用すると、評価やレビューを含む、すべてのロケーションの統計情報を統合できます。Google Business Profileベータ版への参加に興味がある場合は、Treasure Dataカスタマーサクセス担当者にお問い合わせください。

## 前提条件

- Google Business Profileアカウント([www.google.com/business](https://www.google.com/business/))。
- [Google Business Profile前提条件](https://developers.google.com/my-business/content/prereqs)の前提条件リストを完了していること。
- [Treasure Data Toolbelt](https://toolbelt.treasuredata.com/)を含むTreasure Dataの基本知識。


## 'td'コマンドのインストール

[Treasure Data Toolbelt](/tools/cli-and-sdks/td-toolbelt)をインストールします。

## 設定ファイル(load.yml)の作成

### アカウントの場合:


```yaml
in:
    type: google_business_profile
    client_id: my-client-id
    client_secret: secret
    refresh_token: token
    data_type: accounts

filters:
    type: add_time
  - from_value: {mode: upload_time}
    to_column: {name: time}

out: {mode: append}
```

### ロケーションの場合:


```yaml
in:
    type: google_business_profile
    client_id: my-client-id
    client_secret: secret
    refresh_token: token
    data_type: locations

filters:
    type: add_time
  - from_value: {mode: upload_time}
    to_column: {name: time}

out: {mode: append}
```

### ロケーションレビューの場合:


```yaml
in:
    type: google_business_profile
    client_id: my-client-id
    client_secret: secret
    refresh_token: token
    data_type: location_reviews

filters:
    type: add_time
  - from_value: {mode: upload_time}
    to_column: {name: time}

out: {mode: append}
```

### ロケーション日次メトリクス時系列の場合:


```yaml
in:
    type: google_business_profile
    client_id: my-client-id
    client_secret: secret
    refresh_token: token
    data_type: location_daily_metrics_time_series
    daily_metric: BUSINESS_IMPRESSIONS_DESKTOP_MAPS
    start_time: "2014-10-02"
    end_time: "2014-10-03"
    incremental: true

filters:
    type: add_time
  - from_value: {mode: upload_time}
    to_column: {name: time}

out: {mode: append}
```

### ロケーション月次検索キーワードインプレッションの場合:


```yaml
in:
    type: google_business_profile
    client_id: my-client-id
    client_secret: secret
    refresh_token: token
    data_type: location_monthly_search_keywords_impressions
    start_time: "2014-10-02"
    end_time: "2014-10-03"

filters:
    type: add_time
  - from_value: {mode: upload_time}
    to_column: {name: time}

out: {mode: replace}
```

設定キーと説明は以下の通りです:

| **設定キー** | **タイプ** | **必須** | **説明** |
|  --- | --- | --- | --- |
| client_id | string | yes | OAuth client_id。 |
| client_secret | string | yes | OAuth client_secret。 |
| refresh_token | string | yes | OAuth refresh_tokenはaccess_tokenを交換するために使用されます。 |
| data_type | string | yes | インポートするデータのタイプ: `location_reviews`、`accounts`、`locations`、`location_daily_metrics_time_series`、または`location_monthly_search_keywords_impressions` |
| daily_metric | string | yes | サポートされている値は(location_daily_metrics_time_seriesデータタイプにのみ必要):  BUSINESS_IMPRESSIONS_DESKTOP_MAPS,   BUSINESS_IMPRESSIONS_DESKTOP_SEARCH,   BUSINESS_IMPRESSIONS_MOBILE_MAPS,   BUSINESS_IMPRESSIONS_MOBILE_SEARCH,   BUSINESS_CONVERSATIONS,   BUSINESS_DIRECTION_REQUESTS,   CALL_CLICKS,   WEBSITE_CLICKS,   BUSINESS_BOOKINGS,   BUSINESS_FOOD_ORDERS |
| start_time | int | no | - **ロケーション日次メトリクス時系列**: レポート時間範囲の開始時刻(YYYY-MM-DD形式、例: 2022-10-10、範囲は包含的)。 - **ロケーション月次検索キーワードインプレッション**: レポート時間範囲の開始時刻(YYYY-MM形式、例: 2022-10-10、範囲は包含的) |
| end_time | int | no | - **ロケーション日次メトリクス時系列**: レポート時間範囲の終了時刻(YYYY-MM-DD形式、例: 2022-10-10、範囲は包含的)。 - **ロケーション月次検索キーワードインプレッション**: レポート時間範囲の終了時刻(YYYY-MM形式、例: 2022-10-10、範囲は包含的) |
| incremental | boolean | no | インポートを増分にするかどうか。 |
| retry_limit | int | no | 各API呼び出しの最大リトライ回数。デフォルト: 7 |
| initial_retry_wait | int | no | 最初のリトライまでの待機時間。デフォルト: 5秒 |
| max_retry_wait | int | no | リトライ間の最大待機時間。デフォルト: 300秒 |


## ロードジョブの実行

ロードジョブを送信します。データサイズによっては数時間かかる場合があります。ユーザーはデータが保存されるdatabaseとtableを指定する必要があります。


```bash
td connector:issue load.yml \
--database td_sample_db \
--table td_sample_table
```

上記のコマンドは、*database(td_sample_db)*と*table(td_sample_table)*がすでに作成されていることを前提としています。TDにdatabaseまたはtableが存在しない場合、このコマンドは成功しないため、databaseとtableを[手動で](https://docs.treasuredata.com/smart/project-product-documentation/data-management)作成するか、~~`--auto-create-table`オプションを`td connector:issue`~~コマンドと共に使用して、次のようにdatabaseとtableを自動的に作成します。


```
$ td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column created_at --auto-create-table
```

--time-columnオプションを使用して、Time Format列を「Partitioning Key」に割り当てることができます。

# スケジュール実行

定期的なデータインポートのために、定期的なデータコネクタ実行をスケジュールできます。高可用性を確保するために、スケジューラを注意深く設定しています。この機能を使用することで、ローカルデータセンターに`cron`デーモンを配置する必要がなくなります。

## スケジュールの作成

`td connector:create`コマンドを使用して新しいスケジュールを作成できます。スケジュールの名前、cron形式のスケジュール、データが保存されるdatabaseとtable、およびデータコネクタ設定ファイルが必要です。


```bash
td connector:create \
daily_report_import \
"10 0 * * *" \
td_sample_db \
td_sample_table \
load.yml
```

`cron`パラメータは、`@hourly`、`@daily`、`@monthly`の3つの特別なオプションも受け入れます。

## スケジュールのリスト表示

`td connector:list`でスケジュールエントリのリストを確認できます。


```bash
td connector:list
```

## スケジュールの設定と履歴の表示

`td connector:show`は、スケジュールエントリの実行設定を表示します。


```
$ td connector:show daily_report_import
Name     :daily_report_import
Cron     : 10 0 * * *
Timezone : UTC
Delay    : 0
Database : td_sample_db
Table    : td_sample_table
Config
---
// 表示されるload.yml設定。
```

~~`td connector:history`は、スケジュールエントリの実行履歴を表示します。個々の実行結果を調査するには、`td job jobid`~~を使用します。

## スケジュールの削除

`td connector:delete`は、スケジュールを削除します。


```
$ td connector:delete daily_report_import
```