如何无需创建关键词计划,通过Google Ads API获取关键词历史指标?
无需创建关键词计划获取关键词历史指标的Google Ads API方案
你可以直接使用Google Ads API的GenerateHistoricalMetrics服务来获取指定关键词的历史指标,这个服务完全不需要创建关键词计划,也不会返回额外的关键词建议——它的核心作用就是针对你明确指定的关键词,批量查询其历史表现数据。
具体实现步骤
构造目标请求
在请求中直接指定你需要查询的关键词列表,无需配置任何关键词建议相关的参数。你可以根据需求添加地域、语言、时间范围等过滤条件,精准获取对应维度的历史数据。代码示例(Python)
from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.v12.services.types import GenerateHistoricalMetricsRequest def get_historical_keyword_metrics(client, customer_id, keywords): keyword_plan_service = client.get_service("KeywordPlanService") request = GenerateHistoricalMetricsRequest( customer_id=customer_id, keywords=keywords, # 可选:指定地域,比如美国(geo target ID 2840) geo_target_constants=["geoTargetConstants/2840"], # 可选:指定语言,比如英语(language ID 1000) language="languageConstants/1000", # 可选:指定时间范围,默认是过去12个月 # historical_metrics_options=HistoricalMetricsOptions( # time_range=KeywordPlanHistoricalMetricsTimeRange.LAST_12_MONTHS # ) ) response = keyword_plan_service.generate_historical_metrics(request) for result in response.results: keyword = result.text metrics = result.keyword_plan_metrics print(f"关键词: {keyword}") print(f"平均月搜索量: {metrics.avg_monthly_searches}") print(f"首页出价范围(微单位): {metrics.low_top_of_page_bid_micros} - {metrics.high_top_of_page_bid_micros}") print("---") # 初始化客户端(需配置你的认证信息) client = GoogleAdsClient.load_from_storage("google-ads.yaml") # 替换为你的客户ID和目标关键词列表 get_historical_keyword_metrics(client, "123-456-7890", ["你的目标关键词1", "你的目标关键词2"])
关键说明
- GenerateHistoricalMetrics服务和Keyword Idea端点的定位完全不同:前者是查询已有关键词的历史数据,后者是生成新的关键词建议并附带指标,所以用前者就不会出现多余的推荐关键词。
- 你可以一次性传入多个关键词,批量获取数据,大幅提升查询效率。
- 确保你的Google Ads API账号拥有
Keyword Planning相关的权限,否则会出现权限错误。
内容的提问来源于stack exchange,提问作者Bibin Hashley O P
相关产品推荐
相关产品推荐

