问题
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