---
schema_version: "1"
id: 9d1ba7b4364332add57583521cd8b575567fed6ac08dfa21427110115cbec11f
title: Google Sheets Connector 1.1 - 例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/google-sheets-connector/latest/google-sheets-connector-examples.md
canonical_url: https://docs.mulesoft.com/jp/google-sheets-connector/latest/google-sheets-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: bf08c6ffbdea0ee5c47fb20ccbd237a0474824bbc25db47a3c1c14dd58a6f5d5
description: MuleSoft Documentation Site
release: "1.1"
latest: true
---
# Google Sheets Connector 1.1 - 例

次の例は、Google スプレッドシート用 Anypoint Connector (Google Sheets Connector) を使用して既存のスプレッドシートで行を作成する方法を示しています。

## [](#始める前に)始める前に

以下が必要です。

- Google スプレッドシートへのアクセス権
- OAuth のユーザー名とパスワード

## [](#http-リスナーを設定する)HTTP リスナーを設定する

ローカルホストポート 8081 で ​`/`​ アカウントパスへのコールが行われたときに Mule フローを開始するように ​**HTTP リスナー**​を設定します。

この例では一部の項目値に変数を使用しています。次のいずれかを実行できます。

- コード内で変数を値に置き換える。
- プロパティファイルで各変数の値を指定しておき、コネクタ設定からそのファイルを参照する。

プロパティファイルの使い方が分からない場合は、​[「Configuring Property Placeholders (プロパティプレースホルダーの設定)」](https://docs.mulesoft.com/mule-runtime/latest/mule-app-properties-to-configure)​を参照してください。

**HTTP リスナー**​を設定するには、次の手順に従います。

1. Studio で新しい Mule プロジェクトを作成します。
2. **\[Mule Palette (Mule パレット)\]**​ ビューで「​`http`​」を検索し、​**\[Listener\]**​ 操作を選択します。
3. **Listener**​ 操作をキャンバスにドラッグします。
4. **\[Listener\]**​ 設定で、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にある ​**\[+\]**​ をクリックしてグローバル要素を追加します。
5. **\[OK\]**​ をクリックして、デフォルトを受け入れます。
6. **\[Path (パス)\]**​ 項目を ​`/`​ に設定します。

## [](#append-spreadsheets-values-操作を追加および設定する)Append Spreadsheets Values 操作を追加および設定する

1. **\[Mule Palette (Mule パレット)\]**​ ビューで「​`Google Sheets`​」を検索し、​**\[Append Spreadsheets Values\]**​ 操作を選択します。
2. **\[Append Spreadsheets Values\]**​ 操作をキャンバスの ​**\[HTTP Listener\]**​ コンポーネントの右にドラッグします。
3. **\[Append Spreadsheets Values\]**​ 設定で、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にある ​**\[+\]**​ をクリックしてグローバル要素を追加します。
4. 次のようにグローバル要素を設定します。
    
    - **Configuration Name (設定名)**​: `Google_Sheets_Connector_Mule4Connector_Config`
    - **Consumer key (コンシューマーキー)**​: `${config.consumerKey}`
    - **Consumer secret (コンシューマーシークレット)**​: `${config.consumerSecret}`
    - **Authorization url (認証 URL)**​: デフォルトのまま
    - **Access token url (アクセストークン URL)**​: デフォルトのまま
    - **Callback path (コールバックパス)**​: `${config.callbackPath}`
    - **Authorize path (認証パス)**​: `${config.authorizePath}`
5. **\[Test Connection (テスト接続)\]**​ をクリックして、でユーザー名、パスワード、テナント名が正しいことを確認します。
6. **\[OK\]**​ をクリックします。

## [](#append-spreadsheets-values-操作の必須パラメーターを設定する)Append Spreadsheets Values 操作の必須パラメーターを設定する

1. **\[Append Spreadsheets Values\]**​ コンポーネントをクリックします。
2. コンポーネントの設定パネルに、次のパラメーターの独自の値を入力します。たとえば、次のように入力します。
    
    - **Spreadsheet id (スプレッドシート ID)**​: `19y7nVZPQz3NQSTSGfCh06KXPIqGV2YXohTupmynJyZ5`
    - **range (範囲)**​: `Sheet1!A1`
3. **\[OK\]**​ をクリックします。

## [](#mule-コンソールに応答を出力するロガーを追加する)Mule コンソールに応答を出力するロガーを追加する

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、​`logger`​ を検索して ​**\[Logger (Core) (Logger (コア))\]**​ を選択します。
2. **\[Logger\]**​ コンポーネントをキャンバスの ​**\[Append Spreadsheets Values\]**​ コンポーネントの右にドラッグします。
3. 次の項目を設定します。
    
    <table class="tableblock frame-all grid-all fit-content spread">
<colgroup>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">項目</th>
<th class="tableblock halign-left valign-top">値</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Display Name (表示名)</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">「​<code>Log Response</code>​」と入力します。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Message (メッセージ)</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">「​<code>`​#[payload]​`</code>​」と入力します。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Level (レベル)</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">デフォルト (​<code>INFO</code>​) のままにします。</p></td>
</tr>
</tbody>
</table>
4. この例で使用されているプロパティを使用して、​`src/main/resources`​ に ​`mule-artifact.properties`​ という名前のプロパティファイルを作成します。
    
    - `config.consumerKey`
    - `config.consumerSecret`
    - `config.callbackPath`
    - `config.authorizePath`
5. プロジェクトを保存します。
6. ポート 8081 で ​`/`​ に要求を送信してアプリケーションをテストします。
7. 次のような JSON 応答を受信します。

```xml
{
    "spreadsheetId": "19y7nVZPQz3NQSTSGfCh06KXPIqGV2YXohTupmynJyZ5",
    "tableRange": "Demo!A1:C38",
    "updates": {
        "spreadsheetId": "19y7nVZPQz3NQSTSGfCh06KXPIqGV2YXohTupmynJyZ5",
        "updatedRange": "Demo!A39"
    }
}
```

## [](#スプレッドシートでの-append-spreadsheets-values-の例)スプレッドシートでの Append Spreadsheets Values の例

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:google-sheets="http://www.mulesoft.org/schema/mule/google-sheets" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/google-sheets http://www.mulesoft.org/schema/mule/google-sheets/current/mule-google-sheets.xsd">
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="a841f003-9ac4-43bc-8751-10dd557b66d6" >
		<http:listener-connection host="127.0.0.1" port="8081" />
	</http:listener-config>

	<configuration-properties doc:name="Configuration properties" doc:id="7d6911bb-52b4-4d90-8724-62cfe239686a" file="mule-artifact.properties" />

    <flow name="demoFlow" doc:id="481ac26c-b66b-4f9d-b91f-4995ea8ff6a6" >
		<http:listener doc:name="Listener" doc:id="49be04b5-efec-4db6-8c49-d13475533be0" config-ref="HTTP_Listener_config" path="/"/>
		<google-sheets:create-spreadsheets-values-rangeappend-by-spreadsheet-id doc:name="Append Spreadsheets Values" doc:id="2618426a-cca7-41f0-87b2-90ea85045af2" config-ref="Google_Sheets_Connector_Mule4Connector_Config" spreadsheetId="19y7nVZPQz3NQSTSGfCh06KXPIqGV2YXohTupmynJyZ5" range="Demo"/>
		<logger level="INFO" doc:name="Logger" doc:id="9f7181ff-a7ad-4b0c-8300-07b8bd847672" />
	</flow>
</mule>
```

## [](#関連情報)関連情報

- [Anypoint Connector の概要](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)