如何通过Adwords API获取指定广告系列的按日期排序报告?
How to Fetch a Single Campaign Report with Date Sorting via AdWords API
Absolutely! You can easily retrieve a report for just one specific campaign and have the results sorted by date using the AdWords API. Here's a practical breakdown of the steps and examples to implement this:
1. Core Report Query Logic
The key components are:
- A
WHEREclause to filter for your target campaign ID - Selecting the exact fields you need (CampaignID, AdgroupID, Impressions, Clicks, Date)
- An
ORDER BYclause to sort records by date
Example Report Query
For your required fields, the query would look like this:
SELECT CampaignId, AdGroupId, Impressions, Clicks, Date FROM CAMPAIGN_PERFORMANCE_REPORT WHERE CampaignId = '123456789' -- Replace with your actual Campaign ID ORDER BY Date ASC
- Swap
123456789with your campaign's unique ID - Use
ASCfor oldest-to-newest date order, orDESCfor newest-to-oldest
2. Implementation with Python Client Library
Here’s how to execute this query using the official googleads library (adjust for your preferred language/client):
from googleads import adwords # Initialize AdWords client (ensure your credentials are configured correctly) client = adwords.AdWordsClient.LoadFromStorage() # Get report downloader for your API version report_downloader = client.GetReportDownloader(version='v201809') # Use latest supported version # Define your report query report_query = ( 'SELECT CampaignId, AdGroupId, Impressions, Clicks, Date ' 'FROM CAMPAIGN_PERFORMANCE_REPORT ' 'WHERE CampaignId = "123456789" ' 'ORDER BY Date ASC' ) # Download report as CSV (other formats like XML are supported too) report_data = report_downloader.DownloadReportAsString( report_query, 'CSV', client_customer_id='YOUR_CLIENT_CUSTOMER_ID', # Replace with your account CID skip_report_header=False, skip_column_header=False, skip_report_summary=True, include_zero_impressions=False ) # Process or print the results print(report_data)
Key Notes
- Report Type: We used
CAMPAIGN_PERFORMANCE_REPORThere, but if you want ad-group-level focus, you can switch toADGROUP_PERFORMANCE_REPORT(the filtering/sorting logic stays identical) - Zero Impressions: Set
include_zero_impressions=Trueif you want to include days with no activity - API Version: Always use a currently supported API version to avoid compatibility issues
This will return a report containing only data for your specified campaign, sorted chronologically by date.
内容的提问来源于stack exchange,提问作者kishore
相关产品推荐
相关产品推荐

