> ## 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 媒体爬虫被封禁（Instagram / Threads）

> 如何修复因 robots.txt 或 bot 规则封禁 Meta 媒体爬虫所导致的错误码 440（及相关的 Instagram 138 / Threads 379）。

错误码 **440**（以及与之相关的 Instagram 错误码 **138** / Threads 错误码 **379**）在 Meta 的发布爬虫无法下载你的媒体 URL 时返回——最常见的原因是你的服务器上的 `robots.txt` 或 bot 拦截规则拒绝了该爬虫。

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

## 症状

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

```json Error 440 (primary) theme={"system"}
{
  "status": "error",
  "errors": [{
    "action": "post",
    "code": 440,
    "message": "The social network could not download media from this URL (for example Instagram/Meta error 2207052). Ensure the file is publicly reachable by the platform's crawlers (e.g. facebookexternalhit), via media bucket's robots.txt file, not only in a browser.",
    "details": "Media download has failed.: The media could not be fetched from the provided URI...",
    "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>
  错误码 **440** 是 Ayrshare 专门针对此故障的错误码，其消息中明确提到了 `facebookexternalhit` 和 `robots.txt` —— 如果你看到 440，就说明来到了正确的页面。当上游响应不够明确时，同样的根本原因会以错误码 **138** 返回；138 也会用于宽高比 / 格式问题，因此媒体抓取相关的 138 变体可以通过 `details` 中出现的 `"Restricted by robots.txt"` 或 `"HTTP error code 403"` 来识别。错误码 **379** 不包含 `details` 字段——若 Threads 与 Instagram 440 或 138 同时报错，其根本原因通常相同。
</Note>

## 出现原因

当你通过 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 —— 重复的通配符组是导致规则被丢弃或不一致应用的常见原因。
</Warning>

## 验证 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 class="custom-bullets">
  <li>**正常响应：** HTTP 200 或 206，且响应体为二进制数据。</li>
  <li>**被阻止的响应：** HTTP 403，或空白/HTML 错误页。</li>
</ul>

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

## 若仍未修复

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

<ul class="custom-bullets">
  <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` 内容

## 重试失败的帖子

在解决爬虫访问问题后，请使用 [Retry Post 端点](/apis/post/retry-post) 重试失败的帖子。

## 相关内容

<ul class="custom-bullets">
  <li>[Instagram API](/apis/post/social-networks/instagram)</li>
  <li>[Threads API](/apis/post/social-networks/threads)</li>
  <li>[Instagram 媒体指南](/media-guidelines/instagram)</li>
  <li>[Threads 媒体指南](/media-guidelines/threads)</li>
  <li>[Ayrshare 错误码](/errors/errors-ayrshare#media-fetch--crawler-access-errors)</li>
  <li>[视频发布失败](/help-center/technical-support/video_publishing_fails)</li>
</ul>
