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"
}