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

# Airtable

> Airtableからユーザーのソーシャルメディアアカウントを管理

## 概要

[Airtable](https://www.airtable.com)は、スプレッドシートの構造とデータベースの堅牢な機能をシームレスに組み合わせた、多用途のクラウドベースプラットフォームです。

AirtableのオートメーションスクリプトはJavaScriptで書かれており、AyrshareのAPIと統合することで、Airtable内から直接ソーシャルメディア管理を効率化できます。この統合により、コンテンツの投稿、パフォーマンス指標の分析、コメントの管理を、1つの集中的な場所からユーザーのために行うことができます。

このガイドでは、統合をセットアップする手順を順を追って説明します。

## セットアップ

<Warning>
  Airtableオートメーションスクリプトを実行するには、[有料の](https://airtable.com/pricing)Airtableプランが必要です。
  Airtableプランがスクリプトを含むオートメーションを含んでいることを確認してください。
</Warning>

このガイドでは、[Ayrshare](https://www.ayrshare.com)経由でAirtable内の連携済みソーシャルメディアアカウントに自動投稿する方法を説明します。
単一の企業のソーシャルアカウント、または管理対象クライアントのソーシャルメディアアカウントに投稿できます。以下のコードは、すべて[GitHub](https://github.com/ayrshare/airtable-post-social-media/blob/main/script.js)で入手できます。

<Card horizontal icon="github" href="https://github.com/ayrshare/airtable-post-social-media/blob/main/script.js" title="GitHub: Airtable Post Social Media" />

## API Keyを取得する

まず、[Ayrshareダッシュボード](https://www.ayrshare.com)で無料または有料プランのAPI Keyを取得します。このキーは以下のスクリプトで使用されます。

Ayrshareの[Launch Plan](/multiple-users/business-launch-overview)または[Business Plan](https://www.ayrshare.com/business-plan-for-multiple-users/)を利用しており、クライアントの代わりに投稿したい場合は、/userまたは/create-profileエンドポイント、あるいはAyrshareダッシュボードでクライアントのProfile Keyをすべて収集してください。

<Tip>
  Ayrshareにいくつかのソーシャルアカウントを連携していることを確認してください。[Ayrshareソーシャル連携ページ](https://app.ayrshare.com/social-accounts)で確認してください。
</Tip>

## Airtableワークスペースの作成

[Airtable](https://www.airtable.com)で、フィールドを持つ新しいワークスペースを作成します。セル列の名前は必ず以下のとおりに指定してください:

<ul class="custom-bullets">
  <li>`Post` を Long Textとして</li>

  <li>
    `Platforms` をMulti Selectとして、タイプ: facebook、instagram、twitter、linkedin、reddit、telegram
  </li>

  <li>`Images` を Attachmentとして</li>
  <li>`Profile Keys` を Single Line Textとして</li>
  <li>`Status` を Single Line Textとして。</li>
  <li>`Schedule Date` を Dateとして、Local Format、Include Time Field、Time Format 24 Hours</li>
</ul>

<img class="center" src="https://mintcdn.com/ayrshare-docs/6mPR4kmwNEz1kMbX/images/packages-guides/airtable-example.webp?fit=max&auto=format&n=6mPR4kmwNEz1kMbX&q=85&s=ac8b91e08f67f7c2432ddfbbf7e65aa0" alt="Airtable Table Example" width="1536" height="161" data-path="images/packages-guides/airtable-example.webp" />

これらのフィールドは、これから構築するAirtableオートメーションスクリプトで使用されます。

[ライブのAirtable例](https://airtable.com/shrCWY0oA1ghB42tI/tblpnTEiPwyuViqBo)をご覧ください。

<Card horizontal icon="book-open" href="https://airtable.com/shrCWY0oA1ghB42tI/tblpnTEiPwyuViqBo" title="Airtable ソーシャルメディア例">
  ライブのAirtable例を見る
</Card>

## テスト投稿データを入力する

投稿をテストするためのサンプルデータが必要です。以下は提案です:

<ul class="custom-bullets">
  <li>`Post`: *Happy New Year 2025* と入力</li>

  <li>
    `Platforms`: 連携済みのネットワークを1つ以上選択します。名前は小文字であることを確認してください。
  </li>

  <li>
    `Images`: 画像を添付します。次の画像をダウンロードして添付するのがおすすめです:
    [https://img.ayrshare.com/012/gb.jpg](https://img.ayrshare.com/012/gb.jpg)
  </li>

  <li>
    `Profile Keys`: Business PlanまたはLaunch Planを利用中で、クライアントのプロフィールに投稿したい場合は、そのProfile Keyを入力します。*それ以外の場合は空欄のままにしてください。*
  </li>

  <li>
    `Status`: *pending* と入力します。スクリプトはpendingに設定されたレコードのみを取得します。`pending`は小文字であることを確認してください。
  </li>

  <li>
    `Schedule Date`: 今回は即時投稿をテストするだけなので、空欄のままにします。後で、将来の日付を選択して投稿をスケジュール設定できます。
  </li>
</ul>

## スクリプトエディタでオートメーションスクリプトを構築する

これから、テーブルからデータを読み取り、投稿を作成し、Ayrshare経由でソーシャルネットワークに送信するAirtableオートメーションスクリプトを構築します。Airtableスクリプトエディタを使用します。

### トリガーを追加

* ワークスペースで、*Automation* をクリックし、次に *+New automation* をクリックします。

<img class="center" src="https://mintcdn.com/ayrshare-docs/6mPR4kmwNEz1kMbX/images/packages-guides/new%20automation.webp?fit=max&auto=format&n=6mPR4kmwNEz1kMbX&q=85&s=d2637323e3e540d6e46cf0d45e2f161a" alt="Go to the Automation section of Airtable" width="932" height="144" data-path="images/packages-guides/new automation.webp" />

<ul class="custom-bullets">
  <li>オートメーションに名前を付けます。</li>
  <li>*Choose a Trigger* をクリックします。</li>
  <li>When a Record is Created を選択します。</li>
  <li>上記のフィールドを持つテーブルを選択します。</li>
  <li>Done をクリックします。</li>
</ul>

## アクションを追加

<ul class="custom-bullets">
  <li>*Add Action* をクリックして開始します。</li>
  <li>*Run Script* を選択します。スクリプトエディタに移動します。</li>
</ul>

以下の行を**削除**します:

```javascript theme={"system"}
console.log(`Hello, ${base.name}!`);
```

そしてスクリプトエディタに以下のコードを**コピー&ペースト**します:

```javascript theme={"system"}
const API_KEY = "Your API Key"; // Get a free key at app.ayrshare.com

console.log(`Starting Post ${base.name}!`);

const sendPost = async (data) => {
  const { post, platforms, imageUrls, profileKeys, scheduleDate, shortenLinks } = data;

  const body = Object.assign(
    {},
    post && { post },
    platforms && { platforms },
    profileKeys && { profileKeys: profileKeys.split(",") },
    Array.isArray(imageUrls) &&
      imageUrls.length > 0 && {
        mediaUrls: imageUrls.map((image) => image.url)
      },
    scheduleDate && { scheduleDate },
    shortenLinks !== undefined && shortenLinks !== null && { shortenLinks }
  );

  console.log("Posting JSON:", JSON.stringify(body, null, 2));

  if (profileKeys) {
    body.profileKeys = profileKeys.split(",");
  }

  const response = await fetch("https://api.ayrshare.com/api/post", {
    method: "POST",
    body: JSON.stringify(body),
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${API_KEY}`
    }
  }).then((res) => res.json());

  return response;
};

const table = base.getTable("Posts");
const query = await table.selectRecordsAsync();
const filteredRecords = query.records.filter((record) => {
  const status = record.getCellValue("Status");
  return status === "pending";
});

for (let record of filteredRecords) {
  const post = record.getCellValue("Post");
  const images = record.getCellValue("Images");
  const platforms = record.getCellValue("Platforms");
  const profileKeys = record.getCellValue("Profile Keys");
  const scheduleDate = record.getCellValue("Schedule Date");

  const shortenLinks = false;
  const response = await sendPost({
    post,
    platforms: platforms.map((x) => x.name),
    imageUrls: images,
    profileKeys,
    scheduleDate,
    shortenLinks
  });

  console.log(response);

  if (response) {
    let status;
    if (Array.isArray(response)) {
      status = response.map((x) => x.status).every((x) => x === "success") ? "success" : "error";
    } else {
      status = response.status;
    }

    await table.updateRecordAsync(record, {
      Status: status
    });
  }
}
```

このコードは、テーブルから読み取り、Ayrshareに投稿します。ただし、まず(上記で取得した)API Keyを追加する必要があります。

`Your API Key`を実際のAPI Keyに置き換えてください。

## スクリプトをテストする

スクリプトエディタで、*>Test* を押します。

スクリプトが実行され、API呼び出しからのレスポンスが出力されます。すべてが正常に動作した場合、成功メッセージが返され、レコードのpendingフィールドがsuccessに変更され、選択したソーシャルネットワークに投稿が公開されます。

テーブルに新しいレコードを作成すると、スクリプトが実行され、pendingレコードを処理します。

## Airtableドキュメント

より詳しい情報については、[Airtableドキュメント](https://www.airtable.com/developers)をご覧ください。
Airtableスクリプトエディタの使い方の詳細が記載されています。

## ビデオチュートリアル

Automate All The Thingsのチームによる素晴らしいビデオチュートリアルです。このビデオでは、Ayrshareをライブの Airtableプロジェクトに統合する方法を説明します。

<div class="video-container">
  <iframe width="560" height="315" src="https://www.youtube.com/embed/U_jo6f5hsyY" title="Post To Social Media From Airtable" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" />
</div>

[Airtableとソーシャルメディアの統合例](https://www.ayrshare.com/blog/automatically-post-to-social-media-from-airtable/)をさらにご覧ください。

## ご質問

ご質問やコメントがある場合は、[メール](mailto:contact@ayrshare.com)でお問い合わせいただくか、<a href="javascript:void(0)" onClick={() => window.Intercom && window.Intercom('show')}>チャットでお問い合わせ</a>ください。
