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

# Facebook Page API

> 使用 Facebook API 發布內容的選項

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<Info>
  如果你在連結 Facebook 時遇到問題，請參閱[疑難排解
  指南](/help-center/technical-support/facebook_posting_issues)。
</Info>

## 發布到 Facebook

使用 Facebook API 發布內容需要連結一個 Facebook 粉絲專頁。Facebook 不允許連結個人帳號。

發布含連結與圖片到 Facebook 粉絲專頁的基本貼文 JSON 範例：

```json Facebook Post with Image theme={"system"}
{
  "post": "The best FB post ever #best https://www.facebook.com", // empty string is allowed
  "mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"],
  "platforms": ["facebook"]
}
```

<ul class="custom-bullets">
  <li>
    除非貼文中已包含圖片或影片，否則 Facebook 會自動顯示貼文中連結的預覽。
    上述範例會顯示圖片，若移除圖片，就會改為顯示連結預覽。
  </li>

  <li>
    如果你的影片副檔名不是常見的影片格式（例如 mp4），請使用 `isVideo`
    參數。詳情請參閱 [/post 端點](/apis/post/post)。
  </li>

  <li>
    Facebook 也支援發送不含貼文文字的媒體。如果你不想包含貼文文字，
    請傳送空字串 `post: ""`。
  </li>

  <li>更多資訊請參閱 [Facebook 媒體指南](/media-guidelines/facebook_pages) 與 [Facebook 授權](/dashboard/connect-social-accounts/facebook)。</li>
</ul>

<Warning>
  Facebook 的 API 不支援在單一貼文中同時包含圖片與影片。你
  可以放多張圖片或一部影片，但不能兩者同時。
</Warning>

## 輪播圖片

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

透過 Ayrshare API 的 `carousel` body 參數發布 Facebook 輪播圖片。

```json Facebook Carousel Post theme={"system"}
{
  "faceBookOptions": {
    "carousel": {
      // The URL of the "See More At" button - required
      "link": "URL of See More At...",
      "items": [
        // 2 min, 10 max elements in the array
        {
          "name": "Image name", // optional
          "link": "URL when image clicked", // required
          "picture": "URL of image" // required
        },
        {
          "name": "Image name",
          "link": "URL when image clicked",
          "picture": "URL of image"
        }
      ]
    }
  }
}
```

<ul class="custom-bullets">
  <li>最上層的 `link` 參數是輪播末端的 URL。</li>

  <li>
    `items` 是包含以下值的物件陣列。items 陣列最少 2 個元素、最多 10 個
    元素。
  </li>

  <li>`picture` - 輪播圖片的 URL。</li>
  <li>`link` - 點擊該圖片時的目的 URL。</li>
  <li>`name` -（選填）顯示在每個圖片卡片上的名稱。</li>
</ul>

**注意：** 不要與 `carousel` 同時使用 `media_urls`。若使用 `media_urls`，`carousels` 會被忽略。

更多資訊請參閱我們的 [Facebook 輪播指南](https://www.ayrshare.com/blog/post-a-series-of-facebook-images-as-a-carousel/)。

## Facebook Reels

透過以下 `facebookOptions`，你可以將影片發布到 Facebook Reels。

<Note>
  Meta 對每個已連結的 Facebook 粉絲專頁在任何 24 小時內設有 30 則 Reels 的上限，以防止
  垃圾內容並維持平台品質。此為滾動限制，計算的是最近的 24
  小時，而非日曆日。
</Note>

```json Facebook Reels Post theme={"system"}
{
  "post": "The description of the video",
  "platforms": ["facebook"],
  "mediaUrls": ["https://img.ayrshare.com/012/reel.mp4"],
  "faceBookOptions": {
    "reels": true,
    "title": "Super title for the Reel", // optional
    "thumbNail": "https://img.ayrshare.com/012/reel-thumbnail.jpg" // optional
  }
}
```

<ul class="custom-bullets">
  <li>
    `reels`：設為 `true` 即可將影片發布到 Reels。若要發布到 Facebook
    Reels 為必填。
  </li>

  <li>
    `title`：影片標題，最多 255 個字元。超過 255 個字元的部分會被
    截斷。選填。
  </li>

  <li>
    `thumbNail`：影片的縮圖（封面圖片）。縮圖應為 JPEG 或
    PNG 檔案的 URL，大小應小於 10MB。選填。
  </li>
</ul>

請參閱 [Reels API 影片需求](/media-guidelines/facebook_pages#reels)，或 [使用 Facebook Reels API 的範例](https://www.ayrshare.com/blog/facebook-reels-api-how-to-post-fb-reels-using-a-social-media-api/)。

<Warning>
  Meta 有時對於某些帳號會處理 Facebook Reels 時發生問題。即使回傳錯誤回應，Reel 仍可能已發布成功。

  如果你在 Facebook Reels 上遇到錯誤，建議先檢查該 Reel 的狀態。若貼文 *未被* 發布，你可以嘗試[再發布一次](/apis/post/retry-post)，這通常會成功。

  你可以使用 `verifyReelsUrl` 欄位中的 URL 檢查狀態。請務必使用與原本貼文相同的 Profile Key。請等到 `verifyReelsIn`（10 分鐘後）的時間再檢查 Reel 狀態。若回傳 HTTP 錯誤代碼 `400`，代表發布失敗，你可以再嘗試一次。

  ```json Facebook Reels Post Error theme={"system"}
  {
    "action": "post",
    "status": "error",
    "code": 108,
    "message": "Facebook Error: Facebook cannot process your post at this time. Please try again. ",
    "detailsData": {
      "id": "104619420979033_36930641143",
      "verifyReelsUrl": "https://api.ayrshare.com/history/36930641143?searchPlatformId=true&platform=facebook",
      "verifyReelsIn": "2024-01-26T00:07:05.170Z",
      "postUrl": "https://www.facebook.com/1046194209_36930641143",
      "reels": true
    },
    "retryAvailable": true,
    "platform": "facebook"
  }
  ```
</Warning>

## Facebook Stories

以照片或影片的形式將 Facebook Stories 發布到 Facebook 粉絲專頁。

<ul class="custom-bullets">
  <li>
    Facebook Stories 不支援貼文文字 — `post` 欄位中提供的任何文字（包含
    提及）都會被忽略。
  </li>

  <li>
    上傳為 story 的照片或影片不能是先前已發布的貼文中使用過的媒體。
  </li>

  <li>影片 story 不得超過 60 秒。</li>

  <li>
    請開啟 [Stories Archive](https://www.facebook.com/help/2058997717520567) 才能透過 GET 取得
    stories。
  </li>
</ul>

```json Facebook Stories Post theme={"system"}
{
  "post": "", // Ignored by stories
  "platforms": ["facebook"],
  "mediaUrls": ["https://img.ayrshare.com/012/stories.mp4"],
  "faceBookOptions": {
    "stories": true
  }
}
```

請參閱 [Stories API 圖片與影片需求](/media-guidelines/facebook_pages#stories)。

## 媒體說明

為發布的每張 Facebook 圖片設定媒體說明。

接受字串說明文字的陣列。每個陣列元素必須對應一個媒體 URL。例如 \["This is my best pic", "😃 here is the next one"] 分別對應 `mediaUrls` 中的第 1 個與第 2 個 URL。

```json Facebook Media Captions theme={"system"}
{
  "faceBookOptions": {
    "mediaCaptions": ["This is my best pic", "😃 here is the next one"]
  }
}
```

## 地點標註

Facebook 地點標籤透過 `locationId` 指定，其為 Facebook Page ID 或 Facebook Page 名稱。例如，[Guggenheim Museum](https://www.facebook.com/guggenheimmuseum) 的 Facebook page ID 是 `7640348500`，或 Facebook page 名稱 `"@guggenheimmuseum"`。粉絲專頁必須關聯有實體地點。

```json Facebook Location Tagging theme={"system"}
// Using the Facebook Page Id - must be associated with a location
{
  "faceBookOptions": {
    "locationId": 7640348500 // Guggenheim Museum Page Id
  }
}
```

你可以使用 [brand 端點](/apis/listen/search/fb-page-search) 查詢 `locationId`（Page ID）。請注意，該粉絲專頁必須有列出地點，否則 locationId 會回傳錯誤。

不支援套用於純文字貼文、圖片、Reels 與 Stories。Meta 不支援對影片進行地點標註。

## 受眾鎖定

在 Facebook 上建立 Page 貼文時，可以使用兩種鎖定方式將可見範圍限制在特定受眾：

1. Facebook Targeting：可依年齡、性別、地區與感情狀態等條件定義貼文的受眾。透過設定這些參數，你可以確保只有符合條件的人能看到你的貼文。
2. Facebook Feed Targeting：可進一步微調貼文在目標受眾動態消息中的可見度。

你可以單獨使用其中一種鎖定選項，也可以合併使用。

### Targeting

Facebook targeting 會將發布內容的[受眾限制](https://www.facebook.com/help/352402648173466)於特定人口統計族群。不在這些族群中的人將無法看到該內容。此設定不會覆蓋粉絲專頁層級可能已設定的人口統計限制。

`targeting` 可用的人口統計欄位：

<ul class="custom-bullets">
  <li>
    `ageMin`：限制可看到貼文的最低年齡。可接受的值為 13、15、18、21 或
    25。其他年齡會被拒絕。
  </li>

  <li>
    `countries`：又稱地區圍籬（geofencing），可限制哪些國家可以看到該貼文。以
    [國家代碼](/iso-codes/country) 陣列表示。最多可鎖定 25 個國家。
    若你需要鎖定超過 25 個國家或限制某些國家，請參閱 [Facebook 粉絲專頁國家限制](/help-center/technical-support/facebook_page_country_restrictions)。
  </li>
</ul>

```json Facebook Targeting theme={"system"}
{
    "faceBookOptions": {
        "targeting": {
            "ageMin": 18,
            "countries": ["DE", "BR"]
    }
}
```

### Feed Targeting

Facebook feed targeting 群組中的使用者較有可能看到此貼文，其他人較不容易看到，但仍可能會看到。如果你想確保限制生效，請使用上方的 targeting。

`feedTargeting` 可用的人口統計欄位：

<ul class="custom-bullets">
  <li>
    `ageMin`：限制可看到貼文的最低年齡。整數值為 13 以上。預設為
    0。
  </li>

  <li>`ageMax`：限制可看到貼文的最高年齡。整數值為 65 以下。</li>

  <li>
    `countries`：又稱地區鎖定（geo targeting），可指定哪些國家的使用者能看到
    該貼文。以[國家代碼](/iso-codes/country)陣列表示。
  </li>

  <li>
    `collegeYears`：鎖定大學畢業年齡的使用者觀看該貼文。以大學畢業年份的整數陣列
    表示。
  </li>

  <li>
    `educationStatuses`：鎖定教育程度的使用者觀看該貼文。以整數陣列表示，
    以鎖定不同教育程度。`1` 代表高中、`2` 代表大學部、`3` 代表
    校友。
  </li>

  <li>
    `genders`：鎖定觀看貼文的性別。以整數陣列鎖定特定性別。
    `1` 鎖定所有男性觀看者，`2` 為女性。預設為兩者皆鎖定。
  </li>

  <li>
    `relationshipStatuses`：鎖定觀看貼文的感情狀態。以整數陣列表示，
    以依感情狀態鎖定。`1` 代表單身、`2` 代表 'in a relationship'、`3` 代表
    已婚、`4` 代表已訂婚。預設為全部類型。
  </li>
</ul>

```json Facebook Feed Targeting theme={"system"}
{
  "feedTargeting": {
    "ageMax": 30,
    "ageMin": 26,
    "countries": ["DE", "BR"],
    "genders": [1, 2],
    "relationshipStatuses": [1, 2]
  }
}
```

## 替代文字

為 Facebook 圖片或影片加上替代文字（alt text）。Facebook alt text 是一項無障礙功能，可提供額外的使用者資訊，並協助螢幕閱讀器讀取內容。

請在 `faceBookOptions` 物件中使用 `altText`。

```json Facebook Alt Text theme={"system"}
{
  "faceBookOptions": {
    // Array of Alt Texts
    "altText": ["This is my best pic", "😃 here is the next one"]
  }
}
```

每個 alt text 必須對應到 `mediaUrls` 陣列中的一張圖片或一部影片，並依序套用到每張圖片上。

## 影片縮圖

為 Facebook 影片設定縮圖（封面圖片）。請傳送 PNG 或 JPG 檔案的遠端 URL，尺寸須與影片相同且小於 10 MB。URL 應以 .png 或 .jpg 結尾。

```json Example Facebook Video Thumbnail theme={"system"}
{
  "faceBookOptions": {
    "thumbNail": "https://octodex.github.com/images/Fintechtocat.png"
  }
}
```

## 影片標題

透過 `title` 參數為 Facebook 影片加上標題。

```json Facebook Video Title theme={"system"}
{
  "faceBookOptions": {
    "title": "The best video ever!"
  }
}
```

## 動態 GIF

發布 Facebook 動態 GIF 時，`mediaUrls` 陣列中只允許一個 URL。
如果媒體 URL 不是以 ".gif" 或 ".GIF" 結尾，請將 `isVideo` 欄位設為 `true`。

```json Facebook Animated GIF theme={"system"}
{
  "randomPost": true,
  "platforms": ["facebook"],
  // Set to true if the GIF URL does not end in .gif or .GIF
  "isVideo": false,
  // Only one URL is allowed in the array
  "mediaUrls": ["https://img.ayrshare.com/012/cat.gif"]
}
```

## Facebook 粉絲專頁提及

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

你可以透過在貼文文字中加入 Facebook 粉絲專頁名稱或 Page ID 來提及另一個 Facebook 粉絲專頁（也稱為 Facebook 提及或 Facebook 標註）。
Facebook 不允許提及或標註個人檔案或社團。

用以下 @提及 格式加入提及：

`@page-name` 或 `@[page-id]`

### 使用粉絲專頁名稱提及

使用粉絲專頁名稱的貼文文字範例。你可以從 Facebook URL 找到粉絲專頁名稱，例如 [https://www.facebook.com/Ayrshare](https://www.facebook.com/Ayrshare)

```json Facebook Page Mention with Page Name theme={"system"}
{
  "post": "This is the best social media api by @Ayrshare"
}
```

Ayrshare 會盡力依名稱尋找對應的粉絲專頁，但有時可能會找不到相符的專頁。使用 Page ID 是更可靠的方法。

### 使用 Page ID 提及

使用 Page ID 的貼文文字範例，注意 \[] 的使用。如何取得 Page ID 請參閱下方說明。

```json Facebook Page Mention with Page ID theme={"system"}
{
  "post": "This is the best social media api by @[738681876342836]" // Ayrshare Page ID
}
```

Facebook Page ID 會解析到對應的粉絲專頁，並 ***通知被提及的粉絲專頁***。

<Warning>
  使用粉絲專頁提及請務必謹慎，只提及與你有關聯的粉絲專頁。切勿進行垃圾騷擾。

  當你提及某個粉絲專頁時，**該粉絲專頁的擁有者會透過通知與電子郵件收到提醒**。若有多個粉絲專頁對你的提及提出檢舉，Facebook 可能會停權你的帳號。原則上，你應只標註與你有既有合作關係的粉絲專頁。

  被提及的 Facebook 粉絲專頁**必須允許**其他粉絲專頁提及/標註其專頁。可在該粉絲專頁的一般設定中「Others Tag this Page」啟用提及功能。

  請詳閱關於提及功能的[重要規則](/testing/post-verification#mentions)。
</Warning>

### 找出 Facebook Page ID

#### Brand 端點

你可以使用 [Brand 端點](/apis/brand/overview) 查詢 Facebook 使用者或 Facebook 粉絲專頁。

#### 在 Facebook.com

1. 從 Facebook 動態消息，點擊左側選單中的 **Pages**。
2. 點擊你的粉絲專頁名稱進入你的粉絲專頁。
3. 點擊粉絲專頁頂端的 **About**。若看不到，請點擊 **More**▼。
4. 向下捲動，在 **MORE INFO** 下方找到你的 **Page ID**。

若要查詢你不擁有的粉絲專頁 ID：

<ul class="custom-bullets">
  <li>
    如果 Facebook 粉絲專頁的 URL 類似 `https://www.facebook.com/ayrshare-1234567890`，
    則 ID 為 ***1234567890***。
  </li>

  <li>如果 Facebook 粉絲專頁的 URL 類似：</li>
</ul>

`https://www.facebook.com/pages/ayrshare/123466789203`，則 Page ID 為結尾的數字，例如 **123466789203**。

你可以透過前往 `https://facebook.com/page-id` 來測試 Page ID 是否正確，該網址應能解析到對應的粉絲專頁。

你也可以嘗試 Ayrshare 未提供支援的第三方 Facebook 粉絲專頁查詢工具，例如：[https://lookup-id.com/](https://lookup-id.com/)

如果以上方法都行不通，你可以在瀏覽器中開啟該 Facebook 粉絲專頁並檢視原始碼。在 Chrome 中，右鍵選擇「View Source」，然後搜尋 `owning_profile_id` 或 `profile_id` 來找到 Page ID。

<Warning>
  請詳閱關於提及功能的[重要規則](/testing/post-verification#mentions)。
</Warning>

### 啟用粉絲專頁提及

該粉絲專頁必須允許在貼文與留言中被提及與標註。此功能預設為啟用，但你可以登入 facebook.com 並切換至你的粉絲專頁進行確認。

1. 以粉絲專頁身分檢視時，點擊右上角的粉絲專頁**個人資料圖片**。
2. 點擊 **Settings & Privacy** -> **Settings**。
3. 在 Settings 選單中，點擊 **Privacy**。
4. 點擊 **Page and Tagging**。
5. 向下捲動至 **Reviewing**。
6. 切換設定以允許標註與提及。

## Meta Business Suite

### 草稿貼文

建立 Facebook 草稿貼文，草稿會顯示在 [Meta Business Suite Draft](https://business.facebook.com/latest/posts/draft_posts) 分頁。Facebook 草稿貼文是你已開始撰寫但尚未發布的貼文。你可以先儲存草稿之後再回來編輯，或排程於未來的時間發布。

在 `faceBookOptions` 中加入 `draft` 參數，即可將貼文送出為草稿。適用於純文字、圖片、影片與 Reels 貼文。

```json Facebook Draft Post theme={"system"}
{
  "faceBookOptions": {
    "draft": true
  }
}
```

### 排程發布時間

為 Facebook 貼文設定排程發布時間，該貼文會顯示在 [Meta Business Suite Scheduled Posts](https://business.facebook.com/latest/posts/scheduled_posts) 分頁。Facebook 排程貼文是指你已建立並排程在未來日期發布，並在 Meta Business Suite 中管理的貼文。這適合用於提前規劃你的社群貼文，或在你已知受眾最活躍的時段發布貼文。

適用於純文字、圖片、影片與 Reels 貼文。

<Warning>
  發布時間必須比目前時間至少晚 10 分鐘，且不能超過目前日期的 29 天後。

  除非你需要在 Meta Business Suite 中管理 Facebook 貼文，否則建議使用標準的 [貼文排程日期](/apis/post/overview#schedule-posts)。
</Warning>

在 `faceBookOptions` 中加入 `scheduledPublishDate` 參數以排程貼文時間。

```json Facebook Scheduled Post theme={"system"}
{
  "faceBookOptions": {
    "scheduledPublishDate": "2023-09-28T21:44:06Z" // Future date in UTC
  }
}
```

## 連結預覽

Facebook 貼文會自動為貼文內容中的連結建立連結預覽。
但若你想指定不同的連結，或強制顯示連結預覽，可使用 `link` 參數指定連結的 URL。

```json Facebook Link Preview theme={"system"}
{
  "faceBookOptions": {
    "link": "https://www.ayrshare.com/instagram-hashtag-guide/"
  }
}
```

如果貼文請求中包含 `mediaUrls` 欄位，會顯示媒體而非連結預覽。

## Facebook Ads

Facebook Ads 是將你的貼文推廣給更廣泛受眾的方法。

<Card title="Facebook Ads" href="/apis/ads/overview" horizontal />

## 字元限制

更多資訊請參閱 [Facebook 字元限制](/help-center/technical-support/character_limits#facebook-character-limits)。

## 補充資訊

### 如何在 Facebook 貼文中加入換行或 rich text？

Facebook 貼文中的換行可以使用特殊的[換行字元](/apis/post/overview#line-breaks)加入。

Rich text（例如粗體或斜體）可以透過幾個 [HTML 元素](/apis/post/overview#rich-text-posts) 加到 Facebook 貼文中。

### 為什麼我在貼文上看到「Published by Ayrshare」？

別擔心，這只會顯示在管理員檢視畫面中。更多資訊請參閱[疑難排解指南](/help-center/technical-support/facebook_shows_published_by_ayrshare)。
