0

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

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

您对如何实现它有任何建议吗?另外“我可以将电子邮件 ID 传递到此列表”下面的代码中的字段 = [] 吗?“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,
    ))
4

1 回答 1

0

您应该首先像您已经做的那样创建自定义受众,然后您可以使用 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 DOC

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 Doc TestCase

于 2020-10-05T07:17:11.310 回答