我正在尝试从 API 中提取活动成本/总支出 我对 API 是 100% 的新手,我无法破解它
我想要: 1- 获取每个广告系列的成本 2- 获取显示在 GUI 上的广告系列 ID,而不仅仅是那种奇怪的代码,即 8cdfn 与 1448530943
到目前为止,这是我的python代码
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