> ## 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 也用於長寬比 / 格式問題，因此可從 `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` 的變更可能需要最多 24 小時才會在 Meta 的爬蟲快取中生效。若驗證成功但貼文仍失敗，請稍後再重試。
</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>**簽章 URL / 預簽章 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` 內容

## 重試失敗的貼文

在你解決爬蟲存取問題後，請使用[重試貼文端點](/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>
