> ## 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 主页 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 存档](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 主页 ID 或 Facebook 主页名称。例如，[Guggenheim Museum](https://www.facebook.com/guggenheimmuseum) 的 Facebook 主页 ID 是 `7640348500`，或 Facebook 主页名称 `"@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`（主页 ID）。请注意，该主页必须列出位置，否则 locationId 将返回错误。

在文本帖子、图片、reels 和 stories 上不支持。Meta 不支持视频进行位置标记。

## 受众定向

在 Facebook 上创建主页帖子时，你可以选择使用两种类型的定向来限制其对特定受众的可见性：

1. Facebook 定向：这允许你根据年龄、性别、位置和关系等因素定义帖子的受众。通过设置这些参数，你可以确保帖子仅显示给符合指定条件的人。
2. Facebook Feed 定向：此选项使你能够进一步优化帖子在目标受众动态中的可见性。

你可以单独使用其中一个定向选项，也可以将它们组合使用。

### 定向

Facebook 定向 [限制受众](https://www.facebook.com/help/352402648173466) 以将发布内容限于特定的人口统计群体。不在这些人口统计群体中的任何人都无法查看此内容。这不会覆盖任何已经设置的主页级别人口统计限制。

`targeting` 可用的人口统计字段：

<ul class="custom-bullets">
  <li>
    `ageMin`：限制可以查看帖子的最低年龄。接受的值为 13、15、18、21 或
    25。其他年龄将被拒绝。
  </li>

  <li>
    `countries`：也称为地理围栏，你可以限制可查看帖子的国家/地区。是
    [国家/地区代码](/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 定向

在这些 Facebook feed 定向组中的任何人更有可能看到此帖子，其他人不太可能，但仍可能看到它。如果你想保证限制，请使用上面的 targeting。

`feedTargeting` 可用的人口统计字段：

<ul class="custom-bullets">
  <li>
    `ageMin`：限制可以查看帖子的最低年龄。整数值 13 或更高。默认为
    0。
  </li>

  <li>`ageMax`：限制可以查看帖子的最高年龄。整数值 65 或更低。</li>

  <li>
    `countries`：也称为地理定向，你可以指定应该能够
    查看帖子的国家/地区。是 [国家/地区代码](/iso-codes/country) 的数组。
  </li>

  <li>
    `collegeYears`：定向大学毕业年龄以查看帖子。整数数组，表示
    大学毕业年份。
  </li>

  <li>
    `educationStatuses`：定向教育状态以查看帖子。整数数组用于
    根据教育水平定向。`1` 表示高中，`2` 表示本科，`3` 表示
    校友。
  </li>

  <li>
    `genders`：定向性别以查看帖子。整数数组用于定向特定性别。
    `1` 定向所有男性观看者，`2` 定向女性。默认为同时定向两者。
  </li>

  <li>
    `relationshipStatuses`：定向关系状态以查看帖子。整数数组用于
    根据关系状态定向。`1` 表示单身，`2` 表示 '恋爱中'，`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 替代文本是一项无障碍功能，用于提供附加的用户信息并支持屏幕阅读器。

在 `faceBookOptions` 对象中使用 `altText`。

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

每条替代文本必须对应 `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 主页名称或主页 ID 来提及其他 Facebook 主页（也称为 Facebook 提及或 Facebook 标记）。
Facebook 不允许提及或标记个人资料或群组。

使用以下 @mention 包含提及：

`@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 会尽最大努力根据名称找到匹配的主页，但有时可能找不到匹配项。更可靠的方法是使用主页 ID。

### 使用主页 ID 提及

带主页 ID 的示例帖子文本；请注意 \[] 的使用。请参见下方了解如何找到主页 ID。

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

Facebook 主页 ID 将解析为匹配的主页并\_**通知被提及的主页**\_。

<Warning>
  使用主页提及时要谨慎，只提及与你有关联的主页。切勿发送垃圾内容。

  当你提及某个主页时，**该主页的所有者将通过警报和电子邮件收到通知**。如果几个主页对你提及他们表示投诉，Facebook 可能会封禁你的账户。通常你只应标记与你有已建立关系的主页。

  被提及的 Facebook 主页**必须允许**其他主页提及/标记他们的主页。可以在主页的常规设置中的 "Others Tag this Page" 下启用提及。

  请查看提及功能的[重要规则](/testing/post-verification#mentions)。
</Warning>

### 查找 Facebook 主页 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`，则主页 ID 是末尾的数字，例如 **123466789203**。

你可以通过访问 `https://facebook.com/page-id` 来测试主页 ID 是否正确，它将解析为该主页。

你也可以尝试第三方 Facebook 主页查找工具（Ayrshare 不支持），例如：[https://lookup-id.com/](https://lookup-id.com/)

如果所有其他方法都失败，你可以在浏览器中打开 Facebook 主页并查看页面源代码。在 Chrome 中，右键单击选择 "查看源代码"。然后搜索 `owning_profile_id` 或 `profile_id` 以找到主页 ID。

<Warning>
  请查看提及功能的[重要规则](/testing/post-verification#mentions)。
</Warning>

### 启用主页提及

该主页必须允许在帖子和评论中提及和标记。默认情况下这是启用的，但你可以通过登录 facebook.com 并切换到你的主页来验证。

1. 以你的主页身份查看，点击右上角你主页的**个人资料图片**。
2. 点击 **Settings & Privacy** -> **Settings**。
3. 在设置菜单中，点击 **Privacy**。
4. 点击 **Page and Tagging**。
5. 向下滚动到 **Reviewing**。
6. 切换设置以允许标记和提及。

## Meta Business Suite

### 草稿帖子

创建一个显示在 [Meta Business Suite 草稿](https://business.facebook.com/latest/posts/draft_posts) 标签中的 Facebook 草稿帖子。Facebook 草稿帖子是你已经开始编写但尚未发布的帖子。你可以保存草稿帖子以便稍后再回来编辑，或者你可以安排它们稍后发布。

将 `draft` 参数添加到 `faceBookOptions` 以将帖子作为草稿发送。适用于文本、图片、视频和 reels 帖子。

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

### 安排发布时间

为 Facebook 帖子设置安排发布时间，这些帖子会出现在 [Meta Business Suite 已安排帖子](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>

将 `scheduledPublishDate` 参数添加到 `faceBookOptions` 以安排发布时间。

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

## 链接预览

Facebook 帖子将自动为帖子正文中的链接创建链接预览。
但是，如果你想指定其他链接或强制显示链接预览，请使用带链接 URL 的 `link` 参数。

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

如果发布请求中包含 `mediaUrls` 字段，将显示媒体而不是链接预览。

## Facebook 广告

Facebook 广告是将你的帖子推广到更广泛受众的一种方式。

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

## 字符限制

更多信息请参见 [Facebook 字符限制](/help-center/technical-support/character_limits#facebook-character-limits)。

## 附加信息

### 如何在 Facebook 帖子中添加换行或富文本？

Facebook 换行可以通过特殊的 [换行字符](/apis/post/overview#line-breaks) 添加到帖子中。

富文本（如粗体或斜体字）可以通过一些 [html 元素](/apis/post/overview#rich-text-posts) 添加到 Facebook 帖子。

### 为什么我在帖子上看到 "Published by Ayrshare"？

不用担心，它只在管理员视图中显示。更多信息请参见 [故障排除指南](/help-center/technical-support/facebook_shows_published_by_ayrshare)。
