> ## 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.

# クイックスタートガイド

> ソーシャルアカウントを連携し、数分で最初の投稿を送信します。

このガイドは単一企業のセットアップを対象としています。複数ユーザーを扱う Business プランおよび Enterprise プランのご購読には、カスタマイズされた統合ガイドをご用意しています。

<div class="video-container">
  <iframe width="560" height="315" src="https://www.youtube.com/embed/HaWh_QOib_Y" title="Ayrshare's Social API Quick Start Guide" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscsope; picture-in-picture" />
</div>

## ソーシャルメディアアカウントを連携する

[Ayrshare アカウント](https://app.ayrshare.com/) にログインまたはサインアップしてください。
Social Account ページで、連携したいソーシャルネットワークをクリックします。
すべての権限を必ず付与してください。

<p align="center">
  <img width="240" src="https://mintcdn.com/ayrshare-docs/dKBti0xVDJrOZ19f/images/fb-connect.webp?fit=max&auto=format&n=dKBti0xVDJrOZ19f&q=85&s=d256f4862cb21b388d388cc62aa94659" alt="Facebook Linking Example" data-path="images/fb-connect.webp" />
</p>

## API Key を取得する

API エンドポイントへのアクセスを認可するには API Key が必要です。
この Key はリクエストのヘッダーで使用し、`Bearer` キーワードを前に付ける必要があります。

API Key は [Ayrshare Dashboard](https://app.ayrshare.com/) の **API Key** ページにあります。必要に応じて **User Profiles** ページで 'Primary Profile' に切り替えてください。
その後、左側パネルにある **API Key** ページを開けます。

<img src="https://mintcdn.com/ayrshare-docs/Nmrhj2Gh7WSf62Bh/images/api-key.webp?fit=max&auto=format&n=Nmrhj2Gh7WSf62Bh&q=85&s=29ebd3dd2f23c9f9f1c52a974ebd6240" alt="API Key" width="4000" height="1126" data-path="images/api-key.webp" />

すべての API 呼び出しでは、ヘッダーに `Bearer` トークンを使って API Key を含める必要があります。また、`Content-Type` として `application/json` も含めてください。

```json Header theme={"system"}
"Authorization": "Bearer API_KEY",
"Content-Type": "application/json"
```

詳細は [Authorization](/apis/overview#authorization) を参照してください。

## 最初の API 投稿を送信する

### 投稿の公開

以下は、当社の API を使ってさまざまなプログラミング言語で投稿する方法を示すコード例です。
さらに簡単に統合するには、事前構築された [SDK パッケージ](/packages-guides/overview) のいずれかを使用できます。

投稿を行うには以下が必要です：

<ul className="custom-bullets">
  <li>認証用の [API Key](/apis/overview#authorization)。</li>
  <li>投稿のテキスト内容。</li>
  <li>投稿先のソーシャルメディアプラットフォーム（連携済みのプラットフォームのみを含めてください）。</li>
  <li>任意: 含めたい画像や動画の URL。</li>
</ul>

すべての例で [/post](/apis/post/post) エンドポイントを使用します。サンプルコードを見てみましょう：

<Info>
  **X/Twitter に投稿する場合は？** X には独自の API 認証情報が必要です。リクエストに 2 つの BYO ヘッダー（`X-Twitter-OAuth1-Api-Key` と `X-Twitter-OAuth1-Api-Secret`）を追加してください。これは **Ayrshare アカウントごとに 1 回限りのセットアップ** であり、同じキーペアがすべてのサブプロファイル／エンドユーザーで機能します。詳細は [セットアップガイド](/dashboard/connect-social-accounts/x-twitter-byo-keys) を参照してください。
</Info>

<CodeGroup>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "post": "Today is a great day!",
    "platforms": ["facebook", "instagram", "linkedin"],
    "mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"]
  }' \
  -X POST https://api.ayrshare.com/api/post
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";

  fetch("https://api.ayrshare.com/api/post", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`
        },
        body: JSON.stringify({
          post: "Today is a great day!", // required
          platforms: ["bluesky", "facebook", "instagram", "linkedin"], // required
          mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"] //optional
        }),
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  payload = {'post': 'Today is a great day!',
          'platforms': ['bluesky', 'facebook', 'instagram', 'linkedin'],
          'mediaUrls': ['https://img.ayrshare.com/012/gb.jpg']}
  headers = {'Content-Type': 'application/json',
          'Authorization': 'Bearer API_KEY'}

  r = requests.post('https://api.ayrshare.com/api/post',
      json=payload,
      headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php

  $curl = curl_init();
  $data = [
      "post" => "Today is a great day!",
      "platforms" => ["bluesky", "facebook", "instagram", "linkedin", "pinterest"],
      "mediaUrls" => ["https://img.ayrshare.com/012/gb.jpg"]
  ];

  curl_setopt_array($curl, [
      CURLOPT_URL => 'https://api.ayrshare.com/api/post',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_POSTFIELDS => json_encode($data),
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer API_KEY', // Replace 'API_KEY' with your actual API key
          'Content-Type: application/json'
      ],
  ]);

  $response = curl_exec($curl);
  curl_close($curl);
  echo $response;
  ```

  ```go Go theme={"system"}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"log"
  	"net/http"
  )

  func main() {
  	message := map[string]interface{}{
  		"post":      "Today is a great day!",
  		"platforms": []string{"bluesky", "facebook", "instagram", "linkedin"},
  		"mediaUrls": []string{"https://img.ayrshare.com/012/gb.jpg"}
  	}

  	bytesRepresentation, err := json.Marshal(message)
  	if err != nil {
  		log.Fatalln(err)
  	}

  	req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/post",
  		bytes.NewBuffer(bytesRepresentation))

  	req.Header.Add("Content-Type", "application/json; charset=UTF-8")
  	req.Header.Add("Authorization", "Bearer API_KEY")

  	res, err := http.DefaultClient.Do(req)
  	if err != nil {
  		log.Fatal("Error:", err)
  	}

  	res.Body.Close()
  }
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;

  namespace PostPOSTRequest_csharp
  {
    class Post
    {
      private static readonly HttpClient client = new HttpClient();

          static async Task Main(string[] args)
          {
              string API_KEY = "API_KEY";
              string url = "https://api.ayrshare.com/api/post";

              // Set up request headers
              client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

              // Prepare JSON content
              string json = "{\"post\" : \"Today is a great day!\","
                  + "\"platforms\" : [ \"bluesky\", \"facebook\", \"instagram\", \"linkedin\" ],"
                  + "\"mediaUrls\" : [ \"https://img.ayrshare.com/012/gb.jpg\" ]}";
              var content = new StringContent(json, Encoding.UTF8, "application/json");

              try
              {
                  // Send POST request
                  HttpResponseMessage response = await client.PostAsync(url, content);
                  response.EnsureSuccessStatusCode();

                  // Read response
                  string responseBody = await response.Content.ReadAsStringAsync();
                  Console.WriteLine(responseBody);
              }
              catch (HttpRequestException e)
              {
                  Console.WriteLine($"Error: {e.Message}");
              }
          }
      }
  }
  ```

  ```ruby Ruby theme={"system"}
  require 'httparty'    # gem install httparty

  res = HTTParty.post("https://api.ayrshare.com/api/post",
      headers: {Authorization: "Bearer API_KEY"},
      body: {
          post: "Today is a great day!",
          platforms: ['bluesky', 'facebook', 'instagram', 'linkedin'],
          mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"]
      }).body

  puts res
  ```
</CodeGroup>

おめでとうございます！最初の投稿を送信できました。

### 投稿レスポンス

当社の API が投稿を正常に処理すると、`status` が "success" のレスポンスを受け取ります。レスポンスには以下が含まれます：

<ul className="custom-bullets">
  <li>`status`: API 呼び出し全体のステータス（"success" または "error"）</li>
  <li>`errors`: 発生したエラーの配列（成功した場合は空）</li>
  <li>`postIds`: プラットフォーム固有の詳細を含むオブジェクトの配列：</li>

  <ul className="custom-bullets">
    <li>プラットフォーム名</li>
    <li>そのプラットフォームでの投稿 ID</li>
    <li>投稿を閲覧するための URL</li>
    <li>その他のプラットフォーム固有の情報</li>
  </ul>
</ul>

`postIds` 配列内の各プラットフォームは独自のステータスを持つため、どのプラットフォームが投稿を正常に受信したかを確認できます。

投稿が正常に処理され、公開されているかを確認するには、ソーシャルメディアページをチェックしてください。プラットフォームによっては、投稿が公開表示されるまで若干の遅延が生じる場合があります。

サンプルレスポンスは以下のとおりです：

```json Post Response theme={"system"}
{
  "status": "success",
  "errors": [],
  "postIds": [
    {
      "status": "success",
      "id": "738681876342836_1530521371228093",
      "postUrl": "https://www.facebook.com/738681876342836/posts/1530521371228093",
      "platform": "facebook"
    },
    {
      "status": "success",
      "id": "18008340650526653",
      "postUrl": "https://www.instagram.com/p/DGf4hgZObR0/",
      "usedQuota": 1,
      "platform": "instagram"
    },
    {
      "status": "success",
      "id": "urn:li:share:7300150903578275840",
      "postUrl": "https://www.linkedin.com/feed/update/urn:li:share:7300150903578275840",
      "owner": "urn:li:organization:66755239",
      "platform": "linkedin"
    }
  ],
  "id": "K0DmYRgugS5P694it",
  "refId": "d93ca2784c9bf7bf83e0bf081d16c91598",
  "post": "Today is a great day!"
}
```

Node.js、Python、PHP、Golang、C#、Ruby でソーシャルメディア API を呼び出すその他のコード例や、その他の優れた機能を確認してください：

<Card title="Post" icon="code" href="/apis/post/post" horizontal />

### もう少し詳しく見る

今回 API 呼び出しをしたときに実際に何が起きたのか、プロセスを分解して見てみましょう。

<Steps>
  <Step title="ヘッダーを設定">
    Header の Authorization bearer トークン（API Key）と content type を json に設定しました。
  </Step>

  <Step title="Body オブジェクトを作成">
    次に、body オブジェクトを作成しました：

    <ul className="custom-bullets">
      <li>"Today is a great day!" というテキストを含む投稿。</li>

      <li>
        Facebook、Instagram、LinkedIn というソーシャルネットワークプラットフォーム。
        Social Linkage ページで連携したプラットフォームのみを含めるようにしてください。
      </li>

      <li>mediaUrls に画像を追加。</li>
    </ul>
  </Step>

  <Step title="/post エンドポイントを呼び出す">
    すべてを /post エンドポイントに HTTP POST として送信しました。
  </Step>
</Steps>

## 出発前に、いくつかのベストプラクティス

### ドキュメントを読む

当社では広範かつ最新のドキュメントを維持しています。すでにここにいらっしゃるので、少し時間を取って左のナビゲーションのドキュメントセクションを確認してみてください。

### エラーコードは重要

ユーザーが優れた体験を得られるよう、これらを適切に処理する必要があります。

<Card title="Errors" icon="link" href="/errors/overview" horizontal />

### API Key を安全に保つ

当社はセキュリティを非常に重視しており、皆さまもそうすべきです。Ayrshare とソーシャルメディアアカウントとの接続はあなたが完全に制御します。アカウントが接続されたら、Ayrshare の API Key が認証手段となります。この Key は秘密にし、安全に保管してください。

### テスト投稿を公開する

[/post エンドポイント](/apis/post/post) の `randomPost`、`randomMediaUrl`、`isLandscapeVideo` または `isPortraitVideo` パラメーターを使って、ランダムな引用、画像、または動画で投稿をテスト公開できます。`randomPost` を使用する場合、`post` パラメーターは不要です。

<div class="video-container">
  <iframe width="560" height="315" src="https://www.youtube.com/embed/hMI0eK-5qBk?si=y5dkygosZ1B2DtlV" title="Post Random Content" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" />
</div>

<Warning>
  これらの投稿はソーシャルメディアページ上でライブ状態になるため、必要に応じてテスト後に削除してください。
</Warning>

#### ランダムな引用

`randomPost: true` を追加することで、投稿公開のテスト用にランダムな引用を送信します。

[/post](/apis/post/post) エンドポイントで使用します。

```json theme={"system"}
"randomPost": true
```

#### ランダムな画像

`randomMediaUrl: true` を追加することで、ランダムな画像を送信します。

[/post](/apis/post/post) エンドポイントで使用します。

```json theme={"system"}
"randomMediaUrl": true
```

#### ランダムな動画

`isVideo: true` と `isLandscapeVideo: true` を追加することで、ランダムな横向き動画を送信します。
動画は標準的な横向きサイズになります。

[/post](/apis/post/post) エンドポイントで使用します。

```json theme={"system"}
"randomMediaUrl": true,
"isLandscapeVideo": true
```

TikTok や Facebook/Instagram Reels に必要な、ランダムな縦向き動画は `isVideo: true` と `isPortraitVideo: true` を追加することで送信できます。

[/post](/apis/post/post) エンドポイントで使用します。

```json theme={"system"}
"randomMediaUrl": true,
"isPortraitVideo": true
```

#### ランダムなコメント

`randomComment: true` を追加することで、コメント公開のテスト用にランダムなコメントを送信します。

[/comment](/apis/comments/post-comment) エンドポイントで使用します。

```json theme={"system"}
"randomComment": true
```

#### cURL 呼び出しの例

ランダムな引用と縦向き動画を送信します。

```bash theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d '{
    "randomPost": true,
    "platforms": ["facebook", "instagram", "linkedin"],
    "randomMediaUrl": true,
    "isPortraitVideo": true
}' \
https://api.ayrshare.com/api/post
```

### **Postman を使って API 呼び出しをテストする**

[Postman](https://www.postman.com/) は API 呼び出しをテストするための素晴らしいツールです。十数言語のコードを生成することもできます。

### デモコード

React と NodeJS のサンプルデモプロジェクトをお探しの場合は、以下の GitHub リポジトリをご覧ください：

<Card title="Github Social Posting Demo App" icon="github" href="https://github.com/ayrshare/social-api-demo" horizontal />

### **よくあるトラブルシューティング**

うまくいかないこともあるので、当社のヘルプセンターに少しヘルプがあります。

<Card title="Troubleshooting" icon="link" href="/help-center/overview" horizontal />

### **お困りの際はお問い合わせください**

サポートいたしますので、右下のチャットまたは [メール](mailto:support@ayrshare.com) でお気軽にお問い合わせください。
