It's not actually a code sample, instead it references another code sample https://developers.google.com/google-ads/api/docs/keyword-planning/generate-forecast-metrics and says what needs to be changed. "Make a request to KeywordPlanService.GenerateHistoricalMetrics after creating the KeywordPlan" and then to "Iterate through each of the KeywordPlanHistoricalMetrics and display each of the metrics."
It apparently needs more changes than that, because if I run it, it executes the historical metrics query successfully and I get a response. Then when I try to iterate through the KeywordPlanHistoricalMetrics objects, it reaches the line
for i, forecast in enumerate(response.keyword_forecasts):
and it crashes with this error:
python-BaseException
Traceback (most recent call last):
File "/home/jason/repo/heimdall/.venv/lib/python3.7/site-packages/proto/message.py", line 600, in getattr
pb_type = self._meta.fields[key].pb_type
KeyError: 'keyword_forecasts'
This response object is opaque and I can't tell what's in it at all. It doesn't seem to have a field called "keyword_forecasts".
This would work out better if you actually provided a working code sample for historical metrics instead of referring to the one for forecast metrics, since you're leaving out some of the details needed to get it to work.
Hello Jason,
Thanks for reaching out to the Google Ads API support. For us to investigate, could you please share the complete logs within the format of the request and response logs with request-id and login-customer-id generated on your end? To get further clarity to investigate further, if possible please share a full screen screenshot of the UI with the date range filter to indicate which activities you are referring to API.
Please send the requested details via the Reply privately to the author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.
For the client library, logging can be enabled by navigating to the Client libraries > Your client library (ex. Python) > Logging documentation, which you can access from this link. ?Let me know if you have further questions.
Best regards,
![]() |
|
||||