我正在尝试使用 python 从 DV360 API 中提取报告。我能找到的唯一方法是使用 sdfdownloadtask。使用 sdfdownloadtask 我能够获取报告,但报告没有印象数、点击数、收入等性能指标。根据文档,这些字段不适用于任何文件类型。 < https://developers.google.com/display-video/api/structed-data-file/v6/Campaign > 有没有办法使用 DV360 API 获取这些指标。
我不知道这是否是the方式,但它是a方式。受到 Fivetran 方法的启发,我最终以类似的方式获取性能指标:
ONE_TIME
查询可能有用的代码:
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient import discovery
PARTNER_ID = "..."
SCOPES = [
"https://www.googleapis.com/auth/display-video",
"https://www.googleapis.com/auth/doubleclickbidmanager",
]
flow = InstalledAppFlow.from_client_secrets_file(
"<path to secrets file>",
scopes=SCOPES
)
credentials = flow.run_local_server()
query = {
"metadata": {
"title": "Default Offline Report",
"dataRange": {"range": "LAST_7_DAYS"},
"format": "CSV",
},
"params": {
"type": "STANDARD",
"groupBys": [
"FILTER_ADVERTISER_NAME",
"FILTER_ADVERTISER",
"FILTER_ADVERTISER_CURRENCY",
"FILTER_INSERTION_ORDER_NAME",
"FILTER_INSERTION_ORDER",
"FILTER_LINE_ITEM_NAME",
"FILTER_LINE_ITEM",
],
"filters": [{"type": "FILTER_PARTNER", "value": f"{PARTNER_ID}"}],
"metrics": [
"METRIC_IMPRESSIONS",
"METRIC_BILLABLE_IMPRESSIONS",
"METRIC_CLICKS",
"METRIC_CTR",
"METRIC_TOTAL_CONVERSIONS",
"METRIC_LAST_CLICKS",
"METRIC_LAST_IMPRESSIONS",
"METRIC_REVENUE_ADVERTISER",
"METRIC_MEDIA_COST_ADVERTISER",
],
"options": {},
},
"schedule": {"frequency": "ONE_TIME"},
}
# create a query, fetch its id
response = service.queries().create(body=query).execute()
queryId = response.get("queryId")
try:
# run a query (i.e., create a report)
response = service.queries().run(queryId=queryId, synchronous=True).execute()
# in case you set synchronous=False (which is done by default), implement polling logic here
# print url to report
print(response["metadata"]["googleCloudStoragePath"])
except Exception as e:
print(e)
service.queries().delete(queryId=queryId).execute()
注意。我建议
ONE_TIME
查询使用 UI,然后提取报告定义以供后续编码工作使用:
service.queries().list().execute()
祝你好运!