I am trying to pull campaign costs/total spend from the API
I am 100% new to the API and I am not able to crack it through
I want to :
1- get cost per campaign
2- get campaign ids that showup on the GUI not just the kind of weird codes ie 8cdfn vs 1448530943
here is my python code so far
from twitter_ads.client import Client
from twitter_ads.cursor import Cursor
from twitter_ads.http import Request
from twitter_ads.error import Error
import time
from twitter_ads.campaign import LineItem
from twitter_ads.enum import METRIC_GROUP
from twitter_ads.enum import GRANULARITY
client = Client(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
account = client.accounts(ACCOUNT_ID)
cids = map(lambda x: x.id, account.campaigns())
resource = ‘/2/stats/accounts/{account_id}/’.format(account_id=account.id)
params = { ‘entity’:‘CAMPAIGN’,
‘entity_ids’:cids,
‘start_time’: ‘2017-12-10’,
‘end_time’:‘2017-12-16’,
‘granularity’:‘TOTAL’,
‘metric_groups’: ‘BILLING’,
‘placement’: ‘PUBLISHER_NETWORK’}
try, build and execute the request with error handling
try:
response = Request(client, ‘get’, resource, params=params).perform()
print(response.body[‘data’])
except Error as e:
# see twitter_ads.error for more details
print e.details
raise
4
Answers
Here is the solution that worked for me the trick is that passing multiple placements doesn't work in the API
I used much of what you initially wrote for a recent requirement of my own. This is what I came up with:
Disclaimer: I was a contributor to pywindsorai.
Assuming you just need the clicks (or spend) data, you can do this using windsor.ai as well, which is a bit simpler to use. You just have to connect your Twitter account to windsor.ai, and then use their Python SDK (pywindsorai) to load the data into pandas.
Im triying to get the same but I cant make it.
I follow all the solution proposed but I received an answer which is the following:
` req =Request(Client, ‘get’, resource, params=params)