Upload email list to Facebook via API

↘锁芯ラ 提交于 2021-02-17 06:22:06

问题


I need to send or create the list of user emails to our business facebook account as an audience list ,so that we can use it for our marketing purposes(I'm using Python 3.8).

Below is the code which i got from Google, But when i searched i found that we cannot directly pass the emails to Facebook via API.

Do you have any suggestions on how to achieve it ? Also "can i pass email ID's to this list "fields = [] in the below code ? AND what does the "ID" means ?

  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,
    ))

回答1:


You should first create the Custom Audience like you already do, then you can add/remove emails with the SDK API (you do not need manually hash the email: the SDK will do it for you). As example:

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

If you take a look of the SDK DOC Here:

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

See also the SDK Doc TestCase here



来源:https://stackoverflow.com/questions/64199243/upload-email-list-to-facebook-via-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!