コード例 #1
0
    print('Error: A minimum of 1 items must be provided for entity_ids')
    sys.exit()

sync_data = []
# Sync/Async endpoint can handle max 20 entity IDs per request
# so split the ids list into multiple requests
for chunk_ids in split_list(ids, 20):
    sync_data.append(LineItem.all_stats(account, chunk_ids, metric_groups))

print(sync_data)

# create async stats jobs and get job ids
queued_job_ids = []
for chunk_ids in split_list(ids, 20):
    queued_job_ids.append(
        LineItem.queue_async_stats_job(account, chunk_ids, metric_groups).id)

print(queued_job_ids)

# let the job complete
seconds = 30
time.sleep(seconds)

async_stats_job_results = LineItem.async_stats_job_result(
    account, job_ids=queued_job_ids)

async_data = []
for result in async_stats_job_results:
    async_data.append(LineItem.async_stats_job_data(account, url=result.url))

print(async_data)
コード例 #2
0
# limit request count and grab the first 10 line items from Cursor
line_items = list(account.line_items(None, count=10))[:10]

# the list of metrics we want to fetch, for a full list of possible metrics
# see: https://dev.twitter.com/ads/analytics/metrics-and-segmentation
metric_groups = [METRIC_GROUP.BILLING]

# fetching stats on the instance
line_items[0].stats(metric_groups)

# fetching stats for multiple line items
ids = map(lambda x: x.id, line_items)
LineItem.all_stats(account, ids, metric_groups)

# fetching async stats on the instance
queued_job = LineItem.queue_async_stats_job(account, ids, metric_groups)

# get the job_id:
job_id = queued_job['id']

# let the job complete
seconds = 15
time.sleep(seconds)

async_stats_job_result = LineItem.async_stats_job_result(account,
                                                         [job_id]).first

async_data = LineItem.async_stats_job_data(account,
                                           async_stats_job_result['url'])
コード例 #3
0
# load the advertiser account instance
account = client.accounts(ACCOUNT_ID)

# limit request count and grab the first 10 line items from Cursor
line_items = list(account.line_items(None, count=10))[:10]

# the list of metrics we want to fetch, for a full list of possible metrics
# see: https://dev.twitter.com/ads/analytics/metrics-and-segmentation
metric_groups = [METRIC_GROUP.BILLING]

# fetching stats on the instance
line_items[0].stats(metric_groups)

# fetching stats for multiple line items
ids = map(lambda x: x.id, line_items)
LineItem.all_stats(account, ids, metric_groups)

# fetching async stats on the instance
queued_job = LineItem.queue_async_stats_job(account, ids, metric_groups)

# get the job_id:
job_id = queued_job['id']

# let the job complete
seconds = 15
time.sleep(seconds)

async_stats_job_result = LineItem.async_stats_job_result(account, job_id)

async_data = LineItem.async_stats_job_data(account, async_stats_job_result['url'])