Update a Tailored Audience using Python SDK

python

#1

Hi All!

I would like to update (add emails/device ids etc.) a Tailored Audience using Python SDK. There is an example in the repo (https://github.com/twitterdev/twitter-python-ads-sdk) how to create and subsequently update an audience, however, I would like to update an already existing one by providing the audience’s id. I would need to do something like this:

$ audience = TailoredAudience(‘audience_id’)

I also tried updating the email list via twurl:

$ twurl -X POST -H ads-api.twitter.com “/3/accounts/account_id/tailored_audience_changes?tailored_audience_id=audience_id&operation=ADD&input_file_path=file_path” | jq

And the change is registered when I check tailored audiences changes via:

$ twurl --trace -H ads-api.twitter.com “/3/accounts/account_id/tailored_audience_changes” | jq

However, the emails are not added to the list when I check the tailored audience size.

Do you know how to solve this issue?
Many thanks in advance!


#2

The size takes both time and exceeding a certain threshold to update (has to exceed a certain % of change because of user privacy). It could be normal for it to not change if it was a small size. Especially if you saw the same behavior with twurl I’m not sure if there is a problem with SDK, please let us know if you still think there is an issue!

Thanks,

John


#3

@JBabichJapan

Hi John,

Thanks for you answer. I have modified the tailored audience more than two days ago with around 100k email addresses as a test and it is still not reflected in the audience size in the Audience Manager. So I think there might be some issue.

Best!


#4

@BuxApi: In terms of how to use the SDK to update an audience, please see the following.

from twitter_ads.audience import TailoredAudience
from twitter_ads.enum import TA_LIST_TYPES, TA_OPERATIONS
# plus any other imports you need

# retrieve a specific tailored audience
>>> ta = TailoredAudience.load(account, id="abc123")

# update that tailored audience
>>> ta.update("file.txt", TA_LIST_TYPES.TWITTER_ID, TA_OPERATIONS.ADD)

I hope this helps.

Thanks!


#5

Hi @juanshishido,

Thank you for your message. I have used the exact same steps you have showed and I still cannot update the audiences.

After running the update method, I obtain:

<TailoredAudience resource at 0x10dd5f080 id=2nd7z>

The load method works fine as I see the loaded Audience. However, after I try updating with a csv/txt file (or tempfile created using tempfile library) there is no change in the audience whatsoever. The updated_at method also shows that it was not updated recently.

Kind regards!


#6

Hey @BuxApi

This is likely due to the fact that Audiences generally take a few days to update, and therefore no visible changes are made to the updated_at timestamp or audience size.

I’d recommend polling the GET tailored_audience_changes to confirm that your updates are being processed.

Thanks!