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

# 受眾成員

> 傳送電子郵件、電話或其他識別碼的 SHA-256 雜湊，向 Facebook 顧客名單受眾新增或移除人員。

向透過[建立受眾](https://www.ayrshare.com/docs/apis/ads/facebook/create-audience.md)建立的顧客名單受眾（`type: customerList`）新增人員，或將其移除。你以標準化識別碼的 SHA-256 雜湊形式傳送每個人；Meta 將雜湊與帳戶比對；原始值永遠不會離開你的系統。

`DELETE /ads/facebook/audiences/{id}/users` 接受相同的請求本文，改為移除這些人員。

<ul>
  <li>當 Meta 比對到至少 100 人後，名單即可用於推廣，這最多可能需要 48 小時。屆時[受眾](https://www.ayrshare.com/docs/apis/ads/facebook/get-audiences.md)會顯示 `status.ready`。</li>
  <li>每個請求最多包含 10,000 列，請求本文最大 10 MiB。較大的名單請分成多個請求傳送。</li>
  <li>透過 GraphQL，`addAdAudienceUsers` 和 `removeAdAudienceUsers` 承載的批次較小：一個 `schema` 欄時約 900 列，欄越多列越少。更大的 GraphQL 請求會收到 `Request body too large.` 請將完整的 10,000 列批次傳送到這些 REST 端點。</li>
  <li>如果較大上傳中的某個請求失敗，之前的請求仍會保留在受眾中。重新傳送失敗的請求即可：Meta 會將重複的列去除。</li>
  <li>ID 必須是 `accountId` 指定之廣告帳戶上的自訂受眾。任何其他 ID 都會傳回帶有 `code: 101` 的 `400`。</li>
</ul>

## 雜湊識別碼屬於個人資料

根據 GDPR 及類似法律，經過雜湊處理的電子郵件或電話號碼仍屬於個人資料。上傳名單時：

<ul>
  <li>**你是資料控管者。** 你需要合法依據（通常是名單中人員的同意）才能將他們的資料用於廣告，這是你的隱私權政策和 Meta 的 [Custom Audience 條款](https://www.facebook.com/legal/terms/customaudience)所要求的。</li>
  <li>**Ayrshare 是資料處理者。** 我們將雜湊傳遞給 Meta，除計數外不保留任何內容：請求本文中的任何列都不會被記錄、快取或儲存，回應也絕不會回顯任何列。</li>
  <li>**你在傳送前進行雜湊。** Ayrshare 絕不會替你進行雜湊。不是雜湊的值會在向 Meta 傳送任何內容之前被拒絕。</li>
</ul>

### 如何進行雜湊

依照 Meta 的[顧客名單規則](https://developers.facebook.com/docs/marketing-api/audiences/guides/custom-audiences#hash)將每個值標準化，然後以 SHA-256 進行雜湊，並以 64 個小寫十六進位字元傳送結果。簡而言之：

<ul>
  <li>`EMAIL`：去除空白並轉為小寫，例如 `jane@example.com`。</li>
  <li>`PHONE`：僅數字，包含國碼，不含開頭的零或 `+`，例如 `14155551234`。</li>
  <li>`FN`、`LN`、`CT`、`ST`、`COUNTRY`：小寫，不含標點或空白；`COUNTRY` 使用兩個字母的代碼；美國州的 `ST` 使用兩個字母的代碼，其他情況使用地區名稱。</li>
  <li>`ZIP`：小寫，不含空白；美國郵遞區號取前五位數字。</li>
  <li>`GEN`：`m` 或 `f`。`DOBY`：四位數年份。`DOBM` 和 `DOBD`：兩位數字。</li>
  <li>`FI`：名字的首字母，小寫。</li>
</ul>

Meta 的頁面提供完整規則，包括其他國家格式的規則。

## 請求頭參數

**Authorization** `string` *required*

[API Key](https://www.ayrshare.com/docs/apis/overview.md#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`
**Profile-Key** `string`

[Profile Key](https://www.ayrshare.com/docs/apis/overview.md#profile-key-format) of a User Profile.

Format: `Profile-Key: PROFILE_KEY`

## 路徑參數

**id** `string` *required*

顧客名單受眾 ID，來自[建立受眾](https://www.ayrshare.com/docs/apis/ads/facebook/create-audience.md)或[受眾](https://www.ayrshare.com/docs/apis/ads/facebook/get-audiences.md)。

## 請求體參數

**accountId** `string` *required*

受眾所屬的廣告帳戶，帶或不帶 `act_` 前綴皆可。

**schema** `array` *required*

每欄中的識別碼，依序排列。支援：`EMAIL`、`PHONE`、`GEN`、`DOBY`、`DOBM`、`DOBD`、`FN`、`LN`、`FI`、`CT`、`ST`、`ZIP`、`COUNTRY`。Meta 接受未經雜湊的 `MADID`、`EXTERN_ID` 和 `PAGEUID`，因此這裡不接受它們。

**data** `array` *required*

每人一列：一個陣列，每個 `schema` 欄對應一個 SHA-256 雜湊，以 64 個小寫十六進位字元表示。最多 10,000 列。

不是此類雜湊的儲存格、寬度錯誤的列或不受支援的金鑰，會在向 Meta 傳送任何內容之前傳回帶有 `code: 101` 的 `400`。訊息會指出列和欄，但絕不包含值，例如 `data[1][0] (EMAIL) is not a hash: expected 64 lowercase hex characters.`

## 回應

僅包含計數：

<ul>
  <li>`received`：Meta 接收的列數。</li>
  <li>`invalid`：Meta 無法讀取的列數。</li>
  <li>`batches`：傳送這些列所用的上傳次數。</li>
</ul>

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users \
-d '{"accountId": "1234567890", "schema": ["EMAIL", "PHONE"], "data": [["5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7", "a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"]]}'
```

```javascript JavaScript theme={"system"}
const API_KEY = "API_KEY";

fetch("https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
    "accountId": "1234567890",
    "schema": [
      "EMAIL",
      "PHONE"
    ],
    "data": [
      [
        "5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
        "a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
      ]
    ]
  })
    })
      .then((res) => res.json())
      .then((json) => console.log(json))
      .catch(console.error);
```

```python Python theme={"system"}
import requests

headers = {'Authorization': 'Bearer API_KEY', 'Content-Type': 'application/json'}
payload = {
  "accountId": "1234567890",
  "schema": [
    "EMAIL",
    "PHONE"
  ],
  "data": [
    [
      "5f4dcc3b5aa765d61d8327deb882cf99b8f0e2e1f6b0d3c0a9b3b2f1e0d9c8b7",
      "a3f1c2d4e5f60718293a4b5c6d7e8f9012345678abcdef0123456789abcdef01"
    ]
  ]
}

r = requests.post('https://api.ayrshare.com/api/ads/facebook/audiences/23851234567890123/users', json=payload, headers=headers)

print(r.json())
```

```json 200: Success theme={"system"}
{
  "status": "success",
  "id": "23851234567890123",
  "received": 1,
  "invalid": 0,
  "batches": 1
}
```

```json 400: A raw value theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 101,
  "message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
  "details": "data[0][0] (EMAIL) is not a hash: expected 64 lowercase hex characters."
}
```

```json 400: Too many rows theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 101,
  "message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
  "details": "data has 12000 rows; the limit is 10000 per request."
}
```

```json 400: Not an audience of this account theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 101,
  "message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
  "details": "id 23851234567890123 is not a custom audience of ad account 123456789."
}
```

```json 413: Body over 10 MiB theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 525,
  "message": "The request body is too large. Please reduce the size of the request."
}
```

```json 400: Meta refused the upload theme={"system"}
{
  "action": "ads",
  "status": "error",
  "code": 369,
  "message": "Unable to add people to the audience. Please try again.",
  "details": "Meta's reason"
}
```


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