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

# Meta 媒体爬虫被封禁

> robots.txt 或 WAF 阻止 Meta 的 facebookexternalhit 爬虫时，如何修复 error 479 并用 curl 验证访问。

错误码 **479** 是 Ayrshare 在 Meta 无法获取你的媒体 URL 时返回的专用且**不可重试**的错误码，最常见的原因是你的服务器上的 `robots.txt` 或 bot 拦截规则拒绝了该爬虫（`facebookexternalhit`）。只有在 Ayrshare 的自动重新托管回退也失败后才会返回该错误码，这强烈表明问题出在托管端的拦截或源文件无法访问。

当 Ayrshare 向 Instagram 或 Threads 发布内容时，它不会只是把你的 URL 交给 Meta 然后就放弃。Ayrshare 会自动重试抓取；如果 Meta 仍然无法访问该媒体，Ayrshare 会**在自己的 CDN 上重新托管一份副本**，并让 Meta 改为抓取该副本。错误码 **479** 表示即使经过这一回退，Meta 仍无法获取该媒体，因此在底层托管问题修复之前，重试同一请求不会有帮助（`retryAvailable: false`，HTTP 400）。

> [!NOTE]
>
> 本页针对的是错误信息或详情中提到社交网络无法下载媒体的失败情况，通常涉及 `facebookexternalhit`、`robots.txt`、`"Restricted by robots.txt"`、`"HTTP error code 403"` 或 Meta 子代码 `2207052`。若是 Instagram 错误码 138 中的宽高比或格式问题，请改为参见 [Instagram 媒体指南](https://www.ayrshare.com/docs/media-guidelines/instagram.md) 或 [Threads 媒体指南](https://www.ayrshare.com/docs/media-guidelines/threads.md)。

## 症状

当爬虫被阻止时，你会看到类似以下的错误：

```json Error 479 (primary — dedicated, non-retryable) theme={"system"}
{
  "status": "error",
  "errors": [{
    "action": "post",
    "code": 479,
    "retryAvailable": false,
    "message": "The social network could not fetch the media from this URL, even after Ayrshare re-hosted it on its own CDN (Instagram/Meta subcode 2207052). Ensure the file is publicly reachable by Meta's crawlers (facebookexternalhit / Facebot) — check your robots.txt and any WAF/bot rules — not only in a browser. Retrying the same URL will not help until hosting is fixed.",
    "details": "Media download has failed.: The media could not be fetched from the provided URI. Restricted by robots.txt (HTTP error code 403). Meta subcode 2207052.",
    "platform": "instagram",
    "status": "error"
  }],
  "postIds": [],
  "id": "..."
}
```

```json Error 440 (transient ingestion — retryable) theme={"system"}
{
  "status": "error",
  "errors": [{
    "action": "post",
    "code": 440,
    "retryAvailable": true,
    "message": "The social network could not ingest the media in time. This is usually transient (for example Meta subcode 2207032 'download too slow' or 2207003 'create media fail'). Retry the post.",
    "details": "Media download has failed.: Media download took too long / could not create media...",
    "platform": "instagram",
    "status": "error"
  }],
  "postIds": [],
  "id": "..."
}
```

```json Instagram Error 138 (fallback — less specific upstream response) theme={"system"}
{
  "status": "error",
  "errors": [{
    "retryAvailable": true,
    "status": "error",
    "code": 138,
    "details": "Media download has failed.: The media could not be fetched from the provided URI. Video download failed with: HTTP error code 403. Restricted by robots.txt",
    "action": "post",
    "platform": "instagram",
    "message": "Instagram Error: Instagram cannot process your post at this time. Please try your post again."
  }],
  "postIds": [],
  "id": "..."
}
```

```json Threads Error 379 theme={"system"}
{
  "status": "error",
  "errors": [{
    "status": "error",
    "code": 379,
    "message": "Error posting to Threads.",
    "action": "post",
    "platform": "threads"
  }],
  "postIds": [],
  "id": "..."
}
```

> [!NOTE]
>
> 理解这些错误码之间的区别：
>
> <ul>
>   <li>**错误码 479：专用的媒体抓取 / 爬虫拦截错误（不可重试）。** 这是本页所涵盖故障对应的错误码。当 Meta 无法获取该媒体（子代码 `2207052` 或媒体抓取相关的文本模式）**即使 Ayrshare 已在自己的 CDN 上重新托管该媒体**时，会返回该错误码并带有 `retryAvailable: false`。其消息中明确提到了 `facebookexternalhit` / `Facebot` 和 `robots.txt`。如果你看到 479，就说明来到了正确的页面。请先修复托管问题再重试。</li>
>   <li>**错误码 440：临时性的接入失败（可重试）。** 现在用于真正临时性的接入耗尽情况，即 Meta 子代码 `2207032`（"download too slow"）/ `2207003`（"create media fail"），或未分类的耗尽情况。它带有 `retryAvailable: true`；请通过 [`/post/retry`](https://www.ayrshare.com/docs/apis/post/retry-post) 重试。</li>
>   <li>**错误码 138：不够明确的 Instagram 回退错误。** 当上游响应不够明确时，同样的根本原因会以该错误码返回。138 也会用于宽高比 / 格式问题，因此媒体抓取相关的变体可以通过 `details` 中出现的 `"Restricted by robots.txt"` 或 `"HTTP error code 403"` 来识别。</li>
>   <li>**错误码 379：Threads。** 不包含 `details` 字段。如果 Threads 与 Instagram 479 或 138 同时报错，其根本原因通常相同。</li>
> </ul>

## 出现原因

当你通过 Ayrshare 向 Instagram 或 Threads 发布内容时，Meta 的服务器会从你提供的 URL 抓取媒体。这一服务器端抓取使用 `facebookexternalhit` User-Agent。如果你服务器的 `robots.txt` 禁止该爬虫，或 WAF/bot 防护规则阻止了它，Meta 将无法下载该文件，发布也会因此失败。

Facebook Page 的发布使用的是不同的接入路径，这就是为什么同一个 `mediaUrl` 在 Facebook 上可能可用，但在 Instagram 和 Threads 上却失败。

## 修复方法：更新你的 robots.txt

### 推荐做法：明确允许 Meta，同时保持对其他爬虫开放

将以下规则添加到你的 `robots.txt`：

```txt robots.txt theme={"system"}
User-agent: facebookexternalhit
Allow: /

User-agent: *
Allow: /
```

这会明确允许 Meta 的爬虫，同时保持网站对其他爬虫（Google、Bing 等）开放。

### 进阶做法：仅允许社交平台的爬虫

如果你希望屏蔽大部分爬虫但允许社交媒体平台：

```txt robots.txt theme={"system"}
User-agent: facebookexternalhit
Allow: /

User-agent: Twitterbot
Allow: /

User-agent: LinkedInBot
Allow: /

User-agent: Pinterest
Allow: /

User-agent: *
Disallow: /
```

> [!WARNING]
>
> 请使用**单个** `User-agent: *` 块，并将其放在文件末尾。符合 RFC 9309 的爬虫会将多个通配符组合并为一个，但并非所有解析器都完全遵循 RFC —— 重复的通配符组是导致规则被丢弃或不一致应用的常见原因。

## 验证 Meta 是否能抓取你的 URL

在重试发帖之前，请先验证 Meta 的爬虫现在能否访问你的媒体。运行以下命令，将 `$URL` 替换为你完整的媒体 URL：

```bash theme={"system"}
curl -v --compressed -H "Range: bytes=0-524288" -H "Connection: close" \
  -A "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)" \
  "$URL"
```

<ul>
  <li>**正常响应：** HTTP 200 或 206，且响应体为二进制数据。</li>
  <li>**被阻止的响应：** HTTP 403，或空白/HTML 错误页。</li>
</ul>

> [!NOTE]
>
> 根据 Meta 的文档，`robots.txt` 的更改在 Meta 的爬虫缓存中最长可能需要 24 小时才能生效。若验证成功但发布仍然失败，请等一段时间后再重试。

## 若仍未修复

如果你已经更新了 `robots.txt`，并通过 `curl` 命令验证通过，但仍然失败：

<ul>
  <li>**24 小时的生效延迟** —— Meta 会缓存 `robots.txt`。请在更改后至多等待 24 小时再重试。</li>
  <li>**WAF 或 bot fight 规则** —— Cloudflare Bot Fight Mode、AWS WAF 托管 bot 规则组等服务即使 `robots.txt` 允许，也可能封锁 Meta 爬虫的 IP 段。请检查你的 WAF 日志，并为 `facebookexternalhit` 添加例外。</li>
  <li>**防盗链/Referer 检查** —— 某些 CDN 会阻止来自数据中心 IP 或缺少有效 `Referer` 头的请求。请将 Meta 爬虫加入白名单，或对媒体路径关闭防盗链保护。</li>
  <li>**Signed URL / Presigned URL 过期** —— 如果你的媒体 URL 带有过期时间（S3 预签名 URL 常见），请确保它在 Meta 爬虫抓取之前不会过期。对于已排期的帖子，请生成在排期时间之后仍有效的 URL。</li>
  <li>**托管媒体服务** —— 如果你使用 Cloudinary、Imgix 等无法编辑 `robots.txt` 的服务，请查阅其文档，了解是否提供 Meta/Facebook 爬虫的白名单设置。</li>
</ul>

如果以上都不能解决，请[联系 Ayrshare 支持](https://www.ayrshare.com/contact)，并附上：

* 错误响应中失败的 `postId`
* 上面 `curl` 验证命令的输出
* 你的 `robots.txt` 内容

## 重试失败的帖子

重试行为取决于你收到的错误码：

<ul>
  <li>**错误码 440（临时性，`retryAvailable: true`）**：接入只是超时或遇到了 Meta 的临时错误。请直接使用 [Retry Post 端点](https://www.ayrshare.com/docs/apis/post/retry-post.md) 重试；无需更改你的托管配置。</li>
  <li>**错误码 479（`retryAvailable: false`）**：即使 Ayrshare 已在自己的 CDN 上重新托管该媒体，Meta 仍无法获取，因此重试未作更改且仍被拦截的 URL 会再次失败。**请先修复托管问题**：在 `robots.txt` 和你的 WAF 中允许 Meta 的爬虫（`facebookexternalhit` / `Facebot`），或将媒体重新托管到 Meta 可以访问的 CDN 上。使用上面的 `curl` 命令进行验证，然后通过 [Retry Post 端点](https://www.ayrshare.com/docs/apis/post/retry-post.md) 重试。</li>
</ul>

## 相关内容

<ul>
  <li>[Instagram API](https://www.ayrshare.com/docs/apis/post/social-networks/instagram.md)</li>
  <li>[Threads API](https://www.ayrshare.com/docs/apis/post/social-networks/threads.md)</li>
  <li>[Instagram 媒体指南](https://www.ayrshare.com/docs/media-guidelines/instagram.md)</li>
  <li>[Threads 媒体指南](https://www.ayrshare.com/docs/media-guidelines/threads.md)</li>
  <li>[Ayrshare 错误码](https://www.ayrshare.com/docs/errors/errors-ayrshare.md#media-fetch-crawler-access-errors)</li>
  <li>[视频发布失败](https://www.ayrshare.com/docs/help-center/technical-support/video-publishing-fails.md)</li>
</ul>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.