使用 Python facebook 营销 API 将具有多个键的用户添加到自定义受众
Adding Users with multiple keys to a Custom Audience using Python facebook marketing API
我需要使用多个用户键创建自定义受众,例如:
+-----------+------+-----+----------------------+------------+
| EXTERN_ID | FN | LN | EMAIL | PHONE |
+-----------+------+-----+----------------------+------------+
| 12345 | John | Doe | john.doe@example.com | 1234567890 |
+-----------+------+-----+----------------------+------------+
我可以使用下面给定的代码创建自定义受众:
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.customaudience import CustomAudience
from facebook_business.api import FacebookAdsApi
access_token = '<ACCESS TOKEN>'
app_secret = '<APP SECRET>'
app_id = '<APP ID>'
id = '<ACCNT_ID>'
FacebookAdsApi.init(access_token=access_token)
fields = [
]
params = {
'name': 'TEST',
'subtype': 'CUSTOM',
'description': 'Internal Data',
'customer_file_source': 'USER_PROVIDED_ONLY',
}
print(AdAccount(id).create_custom_audience(
fields=fields,
params=params,
))
但是,如何为创建的受众添加多键用户值呢?我是 Python 和 Facebook SDK 的新手。非常感谢任何帮助。
您可以将用户添加到刚刚创建的自定义受众中,从而创建
// Define your schema
schema = [
customaudience.CustomAudience.Schema.MultiKeySchema.extern_id,
customaudience.CustomAudience.Schema.MultiKeySchema.fn,
customaudience.CustomAudience.Schema.MultiKeySchema.ln,
customaudience.CustomAudience.Schema.MultiKeySchema.email,
customaudience.CustomAudience.Schema.MultiKeySchema.phone,
]
// create the payload
payload = customaudience.CustomAudience.format_params(
schema,[
["12345", "John", "Doe", "john.doe@example.com","1234567890"],
],
is_raw=True,
)
然后就可以使用payload了,例如:
AdAccount(id).get_api_assured().call(
'POST',
('<custom-audience-id>', 'users'),
params=payload,
)
进一步参考:
https://developers.facebook.com/docs/marketing-api/reference/sdks/python/custom-audience/v8.0
我需要使用多个用户键创建自定义受众,例如:
+-----------+------+-----+----------------------+------------+
| EXTERN_ID | FN | LN | EMAIL | PHONE |
+-----------+------+-----+----------------------+------------+
| 12345 | John | Doe | john.doe@example.com | 1234567890 |
+-----------+------+-----+----------------------+------------+
我可以使用下面给定的代码创建自定义受众:
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.customaudience import CustomAudience
from facebook_business.api import FacebookAdsApi
access_token = '<ACCESS TOKEN>'
app_secret = '<APP SECRET>'
app_id = '<APP ID>'
id = '<ACCNT_ID>'
FacebookAdsApi.init(access_token=access_token)
fields = [
]
params = {
'name': 'TEST',
'subtype': 'CUSTOM',
'description': 'Internal Data',
'customer_file_source': 'USER_PROVIDED_ONLY',
}
print(AdAccount(id).create_custom_audience(
fields=fields,
params=params,
))
但是,如何为创建的受众添加多键用户值呢?我是 Python 和 Facebook SDK 的新手。非常感谢任何帮助。
您可以将用户添加到刚刚创建的自定义受众中,从而创建
// Define your schema
schema = [
customaudience.CustomAudience.Schema.MultiKeySchema.extern_id,
customaudience.CustomAudience.Schema.MultiKeySchema.fn,
customaudience.CustomAudience.Schema.MultiKeySchema.ln,
customaudience.CustomAudience.Schema.MultiKeySchema.email,
customaudience.CustomAudience.Schema.MultiKeySchema.phone,
]
// create the payload
payload = customaudience.CustomAudience.format_params(
schema,[
["12345", "John", "Doe", "john.doe@example.com","1234567890"],
],
is_raw=True,
)
然后就可以使用payload了,例如:
AdAccount(id).get_api_assured().call(
'POST',
('<custom-audience-id>', 'users'),
params=payload,
)
进一步参考:
https://developers.facebook.com/docs/marketing-api/reference/sdks/python/custom-audience/v8.0