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

# 共有コネクター

> すべてのアプリユーザーが共有する単一のサービスアカウントを接続します

<div className="dev-docs-banner">
  <div className="dev-docs-banner-content">
    <div className="dev-docs-banner-title">
      開発者向けドキュメントを表示しています
    </div>

    <div className="dev-docs-banner-text">
      このドキュメントは、Base44 開発者プラットフォームで作業する開発者向けです。アプリエディタ内のコネクターについては、{" "}
      <a href="/Integrations/Connectors">コネクターの使用</a>を参照してください。
    </div>
  </div>
</div>

共有コネクターは、アプリ全体に対して 1 つのアカウントを接続します。すべてのアプリユーザーが同じ OAuth トークンを共有します。会社の Slack チャンネルへの投稿、共有 Google カレンダーからの読み取り、共有 Notion ワークスペースへのクエリなど、サービスアカウントに使用してください。

**共有コネクターをセットアップするには:**

1. 必要な各サービス用に JSONC ファイルを[**構成**](#configure)します
2. CLI 経由で[**デプロイして認可**](#deploy-and-authorize)します
3. OAuth コネクターの場合は [`getConnection()`](/developers/references/sdk/docs/interfaces/connectors#getconnection) を呼び出し、決済の場合は [Stripe REST API](#stripe) を直接使用して[**バックエンド関数で使用**](#use-in-backend-functions)します

## 構成

各コネクターは、プロジェクトの connectors ディレクトリ内の JSONC ファイルです。ファイルは、インテグレーションタイプとアプリが必要とするスコープを定義します。デフォルトでは、ディレクトリは `base44/connectors/` ですが、[プロジェクト構成](/developers/backend/overview/project-structure#config-jsonc)でパスをカスタマイズできます。

<Tree>
  <Tree.Folder name="connectors" defaultOpen>
    <Tree.File name="googlecalendar.jsonc" />

    <Tree.File name="slack.jsonc" />

    <Tree.File name="slackbot.jsonc" />

    <Tree.File name="notion.jsonc" />
  </Tree.Folder>
</Tree>

### 例

この例では、読み取りとイベント管理スコープで Google Calendar コネクターを構成します:

```jsonc theme={null}
{
  "type": "googlecalendar",
  "scopes": [
    "https://www.googleapis.com/auth/calendar.readonly",
    "https://www.googleapis.com/auth/calendar.events",
  ],
}
```

### フィールドリファレンス

<ResponseField name="type" type="string" required>
  インテグレーションタイプ識別子。受け入れられる完全な値リストについては、[サポートされるサービス](/developers/backend/resources/connectors#supported-services)テーブルを参照してください。

  各コネクタータイプは、プロジェクトで一度だけ定義できます。
</ResponseField>

<ResponseField name="scopes" type="array" required>
  インテグレーションに必要な OAuth スコープの配列。特定のスコープは外部サービスとアプリが実行する必要のある操作に依存します。各サービスで利用可能なスコープについては、[コネクターの権限とスコープ](/Integrations/Connectors#connector-permissions)ドキュメントを参照してください。
</ResponseField>

## デプロイと認可

[`connectors push`](/developers/references/cli/commands/connectors-push) または [`deploy`](/developers/references/cli/commands/deploy) でコネクターをデプロイします。Base44 から既存のコネクターをダウンロードするには、[`connectors pull`](/developers/references/cli/commands/connectors-pull) を使用してください。

プッシュすると、CLI はタイプに基づいて各コネクターを処理します:

* **OAuth コネクター:** CLI は各コネクターを 1 つずつ認可するように促します。ブラウザを自動的に開くことを提案し、承諾すると各インテグレーションの認可ページを順次反復処理します。認可が完了すると、OAuth トークンが安全に保存され、SDK を使用して取得できます。
* **Stripe:** CLI はアプリ用の Stripe sandbox をプロビジョニングし、オンボーディングを完了するための claim URL を返します。OAuth フローは不要です。

## バックエンド関数で使用する

デプロイされて認可された後、[バックエンド関数](/developers/backend/resources/backend-functions/overview)でコネクターを使用します。アプローチはコネクターの認証モデルによって異なります:

<Tabs>
  <Tab title="OAuth コネクター">
    認証された API 呼び出しを行うための `accessToken` を取得するには、コネクタータイプで [`connectors.getConnection()`](/developers/references/sdk/docs/interfaces/connectors#getconnection) を呼び出してください。一部のコネクターは、追加のパラメータ (サブドメインやアカウント ID など) を含む `connectionConfig` も返します。

    この例では、Google Calendar 接続を取得し、今後のイベントをフェッチします:

    ```typescript theme={null}
    const { accessToken } =
      await base44.asServiceRole.connectors.getConnection("googlecalendar");

    const timeMin = new Date().toISOString();
    const url = `https://www.googleapis.com/calendar/v3/calendars/primary/events?maxResults=10&orderBy=startTime&singleEvents=true&timeMin=${timeMin}`;

    const response = await fetch(url, {
      headers: { Authorization: `Bearer ${accessToken}` },
    });

    const events = await response.json();
    ```
  </Tab>

  <Tab title="Stripe">
    Stripe は `getConnection()` を使用しません。代わりに、コネクターをプロビジョニングするときに、プラットフォームが Stripe API キーをアプリのシークレットとして保存します。バックエンド関数では、環境から `STRIPE_SECRET_KEY` を読み取り、[Stripe REST API](https://docs.stripe.com/api) を直接呼び出してください。

    この例では、Stripe Checkout セッションを作成し、決済 URL を返します:

    ```typescript theme={null}
    const STRIPE_SECRET_KEY = Deno.env.get("STRIPE_SECRET_KEY");

    Deno.serve(async (req) => {
      const { priceId, successUrl, cancelUrl } = await req.json();

      const response = await fetch("https://api.stripe.com/v1/checkout/sessions", {
        method: "POST",
        headers: {
          Authorization: `Bearer ${STRIPE_SECRET_KEY}`,
          "Content-Type": "application/x-www-form-urlencoded",
        },
        body: new URLSearchParams({
          "payment_method_types[]": "card",
          "line_items[0][price]": priceId,
          "line_items[0][quantity]": "1",
          mode: "payment",
          success_url: successUrl || `${req.headers.get("origin")}?success=true`,
          cancel_url: cancelUrl || `${req.headers.get("origin")}?canceled=true`,
        }),
      });

      const session = await response.json();
      return Response.json({ url: session.url });
    });
    ```
  </Tab>
</Tabs>

## コネクター自動化

コネクター自動化を使用すると、バックエンド関数が接続されたサービスのイベントにリアルタイムで応答できます。例えば、Gmail に新しいメールが届いたときや Google Drive のファイルが変更されたときに関数を実行できます。

`function.jsonc` ファイルで、他の自動化と一緒にコネクター自動化を構成してください。完全なフィールドリファレンス、サポートされるイベント、ペイロードドキュメントについては、[コネクター自動化](/developers/backend/resources/backend-functions/automations#connector-automations)を参照してください。

## 関連項目

* [Connectors overview](/developers/backend/resources/connectors)
* [App user connectors](/developers/backend/resources/connectors/app-user-connectors)
* [SDK connectors reference](/developers/references/sdk/docs/interfaces/connectors#getconnection)
* [connectors push](/developers/references/cli/commands/connectors-push)
* [connectors pull](/developers/references/cli/commands/connectors-pull)
* [deploy](/developers/references/cli/commands/deploy)
* [Backend Functions](/developers/backend/resources/backend-functions/overview)
* [Automations](/developers/backend/resources/backend-functions/automations)

<Note>このページは AI を使用して翻訳されました。最も正確で最新の情報については、[英語版](/) を参照してください。 </Note>
