Python Samples

99 views
Skip to first unread message

Alejandro Anaya

unread,
Sep 29, 2020, 3:17:36 PM9/29/20
to Google Ad Manager API Forum
Hi
I'm a newbie using the Google Ad Manager API.

Currently I've configured my python environment in order to connect to my network. The conectivity test running the request 
current_network = network_service.getCurrentNetwork()
And runs fine
But the scripts that I have executed from the documentation examples, they return blank results. The report is generated with the headers (names of the dimensions and metrics) but without records.
For example 
get_top_level_ad_units
get_all_line_items
get_top_level_ad_units
Are a samples that returns empty information, but that script is the only one that returns data

"""Runs a report on Ad Exchange data via the Ad Manager API."""

import tempfile

# Import appropriate modules from the client library.
from googleads import ad_manager
from googleads import errors


def main(client):
# Initialize a DataDownloader.
report_downloader = client.GetDataDownloader(version='v202008')

# Create report job.
report_job = {
'reportQuery': {
'dimensions': ['DATE', 'PLACEMENT_NAME', 'DEVICE_CATEGORY_NAME', 'AGGREGATED_DEMAND_CHANNEL', 'LINE_ITEM_TYPE'],
'columns': ['TOTAL_LINE_ITEM_LEVEL_IMPRESSIONS', 'TOTAL_LINE_ITEM_LEVEL_CLICKS', 'TOTAL_LINE_ITEM_LEVEL_ALL_REVENUE', 'TOTAL_ACTIVE_VIEW_MEASURABLE_IMPRESSIONS', 'TOTAL_ACTIVE_VIEW_VIEWABLE_IMPRESSIONS'],
'dimensionAttributes': ['ADVERTISER_NAME'],
'dateRangeType': 'YESTERDAY'
}
}

try:
# Run the report and wait for it to finish.
report_job_id = report_downloader.WaitForReport(report_job)
except errors.AdManagerReportError as e:
print('Failed to generate report. Error was: %s' % e)

# Change to your preferred export format.
export_format = 'CSV_DUMP'

report_file = tempfile.NamedTemporaryFile(suffix='.csv.gz', delete=False)

# Download report data.
report_downloader.DownloadReportToFile(
report_job_id, export_format, report_file)

report_file.close()

# Display results.
print('Report job with id "%s" downloaded to:\n%s' % (
report_job_id, report_file.name))

if __name__ == '__main__':
# Initialize client object.
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage()
main(ad_manager_client)

What am I doing wrong?

Alejandro Anaya

unread,
Sep 29, 2020, 4:06:59 PM9/29/20
to Google Ad Manager API Forum
*SOLVED*
The service account did not have any team declared, I setup and the scripts now return data.

Raphael Benedeti

unread,
Sep 8, 2021, 2:25:07 PM9/8/21
to Google Ad Manager API Forum
Friend, could you pass me some quick example code just to test some query?

Ad Manager API Forum Advisor

unread,
Sep 9, 2021, 4:02:17 AM9/9/21
to benedeti...@gmail.com, google-doubleclick...@googlegroups.com

Hello Raphael,

Thank you for reaching out to us.

I could see that you've created a new thread with the same concern you mentioned on this thread. For better tracking of issues, let's continue our conversation in the new thread you created.

Regards,

Google Logo
Princess Pamela Pineda
Ad Manager API Team
 


ref:_00D1U1174p._5004Q2NSV8Z:ref
Reply all
Reply to author
Forward
0 new messages