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"]]}'
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);
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())
{
"status": "success",
"id": "23851234567890123",
"received": 1,
"invalid": 0,
"batches": 1
}
{
"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."
}
{
"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."
}
{
"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."
}
{
"action": "request",
"status": "error",
"code": 525,
"message": "The request body is too large. Please reduce the size of the request."
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to add people to the audience. Please try again.",
"details": "Meta's reason"
}
Facebook Ads
受眾成員
傳送電子郵件、電話或其他識別碼的 SHA-256 雜湊,向 Facebook 顧客名單受眾新增或移除人員。
POST
/
ads
/
facebook
/
audiences
/
{id}
/
users
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"]]}'
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);
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())
{
"status": "success",
"id": "23851234567890123",
"received": 1,
"invalid": 0,
"batches": 1
}
{
"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."
}
{
"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."
}
{
"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."
}
{
"action": "request",
"status": "error",
"code": 525,
"message": "The request body is too large. Please reduce the size of the request."
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to add people to the audience. Please try again.",
"details": "Meta's reason"
}
向透過建立受眾建立的顧客名單受眾(
type: customerList)新增人員,或將其移除。你以標準化識別碼的 SHA-256 雜湊形式傳送每個人;Meta 將雜湊與帳戶比對;原始值永遠不會離開你的系統。
DELETE /ads/facebook/audiences/{id}/users 接受相同的請求本文,改為移除這些人員。
- 當 Meta 比對到至少 100 人後,名單即可用於推廣,這最多可能需要 48 小時。屆時受眾會顯示
status.ready。 - 每個請求最多包含 10,000 列,請求本文最大 10 MiB。較大的名單請分成多個請求傳送。
- 透過 GraphQL,
addAdAudienceUsers和removeAdAudienceUsers承載的批次較小:一個schema欄時約 900 列,欄越多列越少。更大的 GraphQL 請求會收到Request body too large.請將完整的 10,000 列批次傳送到這些 REST 端點。 - 如果較大上傳中的某個請求失敗,之前的請求仍會保留在受眾中。重新傳送失敗的請求即可:Meta 會將重複的列去除。
- ID 必須是
accountId指定之廣告帳戶上的自訂受眾。任何其他 ID 都會傳回帶有code: 101的400。
雜湊識別碼屬於個人資料
根據 GDPR 及類似法律,經過雜湊處理的電子郵件或電話號碼仍屬於個人資料。上傳名單時:- 你是資料控管者。 你需要合法依據(通常是名單中人員的同意)才能將他們的資料用於廣告,這是你的隱私權政策和 Meta 的 Custom Audience 條款所要求的。
- Ayrshare 是資料處理者。 我們將雜湊傳遞給 Meta,除計數外不保留任何內容:請求本文中的任何列都不會被記錄、快取或儲存,回應也絕不會回顯任何列。
- 你在傳送前進行雜湊。 Ayrshare 絕不會替你進行雜湊。不是雜湊的值會在向 Meta 傳送任何內容之前被拒絕。
如何進行雜湊
依照 Meta 的顧客名單規則將每個值標準化,然後以 SHA-256 進行雜湊,並以 64 個小寫十六進位字元傳送結果。簡而言之:EMAIL:去除空白並轉為小寫,例如jane@example.com。PHONE:僅數字,包含國碼,不含開頭的零或+,例如14155551234。FN、LN、CT、ST、COUNTRY:小寫,不含標點或空白;COUNTRY使用兩個字母的代碼;美國州的ST使用兩個字母的代碼,其他情況使用地區名稱。ZIP:小寫,不含空白;美國郵遞區號取前五位數字。GEN:m或f。DOBY:四位數年份。DOBM和DOBD:兩位數字。FI:名字的首字母,小寫。
請求頭參數
路徑參數
請求體參數
每欄中的識別碼,依序排列。支援:
EMAIL、PHONE、GEN、DOBY、DOBM、DOBD、FN、LN、FI、CT、ST、ZIP、COUNTRY。Meta 接受未經雜湊的 MADID、EXTERN_ID 和 PAGEUID,因此這裡不接受它們。每人一列:一個陣列,每個
schema 欄對應一個 SHA-256 雜湊,以 64 個小寫十六進位字元表示。最多 10,000 列。不是此類雜湊的儲存格、寬度錯誤的列或不受支援的金鑰,會在向 Meta 傳送任何內容之前傳回帶有 code: 101 的 400。訊息會指出列和欄,但絕不包含值,例如 data[1][0] (EMAIL) is not a hash: expected 64 lowercase hex characters.回應
僅包含計數:received:Meta 接收的列數。invalid:Meta 無法讀取的列數。batches:傳送這些列所用的上傳次數。
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"]]}'
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);
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())
{
"status": "success",
"id": "23851234567890123",
"received": 1,
"invalid": 0,
"batches": 1
}
{
"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."
}
{
"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."
}
{
"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."
}
{
"action": "request",
"status": "error",
"code": 525,
"message": "The request body is too large. Please reduce the size of the request."
}
{
"action": "ads",
"status": "error",
"code": 369,
"message": "Unable to add people to the audience. Please try again.",
"details": "Meta's reason"
}