xdevplatform / twitter-python-ads-sdk

A Twitter supported and maintained Ads API SDK for Python.
https://twitterdev.github.io/twitter-python-ads-sdk/
MIT License
189 stars 106 forks source link

Cannot create custom audiences #302

Closed lime-n closed 1 year ago

lime-n commented 1 year ago

When I attempt to create custom audiences with the following script:

# initialize the client
client = Client(
    CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
aud_create = CustomAudience(ACCOUNT_ID)
aud_create.create(account = ACCOUNT_ID,name='twitter test audience')

I get the following error:

----> 1 aud_create.create(account = ACCOUNT_ID,name='twitter test audience')

c:\Users\iuser\Anaconda3\lib\site-packages\twitter_ads\audience.py in create(klass, account, name)
     29         """
     30         audience = klass(account)
---> 31         getattr(audience, '__create_audience__')(name)
     32         try:
     33             return audience.reload()

c:\Users\iuser\Anaconda3\lib\site-packages\twitter_ads\audience.py in __create_audience__(self, name)
     78     def __create_audience__(self, name):
     79         params = {'name': name}
---> 80         resource = self.RESOURCE_COLLECTION.format(account_id=self.account.id)
     81         response = Request(self.account.client, 'post', resource, params=params).perform()
     82         return self.from_response(response.body['data'])

AttributeError: 'str' object has no attribute 'id'
lime-n commented 1 year ago

I instead needed to do

account = client.accounts(ACCOUNT_ID)
aud_create.create(account = account,name='twitter test audience')