> ## 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** 是 Meta 無法擷取你的媒體 URL 時，Ayrshare 回傳的專用且**無法重試**的代碼。最常見的原因是伺服器上的 `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 subcode `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 **即使在 Ayrshare 將媒體重新託管到自己的 CDN 後**仍無法擷取媒體（subcode `2207052` 或媒體擷取相關的文字模式）時，會以 `retryAvailable: false` 回傳。其訊息會明確提到 `facebookexternalhit` / `Facebot` 與 `robots.txt`，如果看到 479，你就在對的頁面。請先修正託管設定再重試。</li>
>   <li>**代碼 440：暫時性的擷取問題（可重試）。** 現在用於真正暫時性的擷取耗盡，例如 Meta subcode `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` 的變更可能需要最多 24 小時才會在 Meta 的爬蟲快取中生效。若驗證成功但貼文仍失敗，請稍後再重試。

## 若這樣仍無法修復

如果你已更新 `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>**簽章 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` 內容

## 重試失敗的貼文

重試方式取決於你收到的代碼：

<ul>
  <li>**代碼 440（暫時性，`retryAvailable: true`）**：擷取只是逾時，或遇到 Meta 的暫時性錯誤。請直接使用[重試貼文端點](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` 指令驗證後，再透過[重試貼文端點](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.