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

Account object has no attribute trace #219

Open shaun10 opened 5 years ago

shaun10 commented 5 years ago
  File "/opt/conda/lib/python2.7/site-packages/twitter_ads/account.py", line 55, in all
    return Cursor(klass, request, init_with=[client])
  File "/opt/conda/lib/python2.7/site-packages/twitter_ads/cursor.py", line 29, in __init__
    self.__from_response(request.perform())
  File "/opt/conda/lib/python2.7/site-packages/twitter_ads/http.py", line 65, in perform
    if self.client.trace:
AttributeError: 'Account' object has no attribute 'trace'

Is this normal? There is an all method but getting a trace error.

smaeda-ks commented 5 years ago

@shaun10 Please provide your code snippet.

shaun10 commented 5 years ago

entities_df = json_normalize([item.to_params() for item in Account.all(account_object)], sep='_') Account object is an account object iterated over from the below. accounts = client.accounts()

smaeda-ks commented 5 years ago

@shaun10 That seems wrong. When you call accounts = client.accounts() without any arguments, that means you're silently calling Account.all() anyway, so you don't have to do it again. https://github.com/twitterdev/twitter-python-ads-sdk/blob/master/twitter_ads/client.py#L89

shaun10 commented 5 years ago

So doing it again is restricted for the Account? I am trying to use the resource.py to_params to get all of the account information and attributes.

smaeda-ks commented 5 years ago

@shaun10 Why not just do something like:

account_object = client.accounts()
entities_df = json_normalize([item.to_params() for item in account_object], sep='_')
smaeda-ks commented 5 years ago

@shaun10 Let me know if you still have a question for this, or I'll close this later.

shaun10 commented 5 years ago

@smaeda-ks yeah I can do it with the suggested approach but I have to add a conditional statement to the method because I cannot call a generic Object.all() because for Account object all is already called and I cannot re-call the all method.

smaeda-ks commented 5 years ago

@shaun10 Sorry, but I don't get your point. Could you elaborate what's your goal here and what's the problem you're trying to solve?

Since with that approach, entities_df has a list which has all the necessary information you need and I'm wondering why you want to call .all() again.

shaun10 commented 5 years ago

So high level I have a method that is called and takes an entity object and then stores all the returned entities in a data frame to produce lookup data for the account. I have many accounts so I call all on every account for a given entity type then store the results in a table. I take the entity object into the method then call .all to get all of the entities back and store them. I have a predefined column list I use to control what columns I store in the data frame. I then take that and save it to a file and store it in a table. The all is pretty much everything here. I just didn't understand why all could be called on PromotedTweet, MediaLibrary, FundingInstrument etc but not on the Account.

I created lookup tables already for most of these data types but it looks like I can't do it for the Account?