通过API将电子邮件列表上传到Facebook



我需要将用户电子邮件列表作为受众列表发送或创建到我们的企业facebook帐户,以便我们可以将其用于营销目的(我使用的是Python 3.8(。

下面是我从谷歌得到的代码,但当我搜索时,我发现我们无法通过API直接将电子邮件传递到Facebook。

你对如何实现它有什么建议吗?此外;我能把电子邮件ID传给这个列表吗;fields=[]?以及";ID";方法

from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.customaudience import CustomAudience
from facebook_business.api import FacebookAdsApi


access_token = 'EAAi0wZCiZxxxxxxxxxxxxxxxDZD'
app_secret = 'xxxxxxxxxxxxxxx'
app_id = 'xxxxxxxxxxx'
id = '<ID>'
fields = []
FacebookAdsApi.init(access_token=access_token)
print("Access succesful") 
params = {
'name': 'My new Custom Audience',
'subtype': 'CUSTOM',
'description': 'People who purchased on my website',
'customer_file_source': 'USER_PROVIDED_ONLY',
}
print (AdAccount(id).create_custom_audience(
fields=fields,
params=params,
))

您应该首先像您已经做的那样创建自定义受众,然后您可以使用SDK API添加/删除电子邮件(您不需要手动对电子邮件进行哈希:SDK会为您做这件事(。例如:

custom_audience = CustomAudience(DocsDataStore.get('ca_id'))
response = custom_audience.add_users(
schema=CustomAudience.Schema.email_hash,
users=[
'joe@example.com',
]
)

如果你看一下这里的SDK文档:

CustomAudience.add_users (schema, users, is_raw, app_ids, pre_hashed)
pre_hashed: Whether or not the data has already been hashed. If not, the SDK will automatically hash the data

另请参阅此处的SDK文档测试用例

最新更新