Hi 
I'm trying to use keyword planner from API. 
I use script from this site 
https://developers.google.com/google-ads/api/docs/keyword-planning/generate-historical-metrics?hl=en

so something like this :

def generate_historical_metrics(client, customer_id):
    """Generates historical metrics and prints the results.

    Args:
        client: an initialized GoogleAdsClient instance.
        customer_id: a client customer ID.
    """
    googleads_service = client.get_service("GoogleAdsService")
    keyword_plan_idea_service = client.get_service("KeywordPlanIdeaService")
    request = client.get_type("GenerateKeywordHistoricalMetricsRequest")
    request.customer_id = customer_id
    request.keywords = ["mars cruise"]
    # Geo target constant 2840 is for USA.
    request.geo_target_constants.append(
        googleads_service.geo_target_constant_path("2840")
    )
    request.keyword_plan_network = (
        client.enums.KeywordPlanNetworkEnum.GOOGLE_SEARCH
    )
    # Language criteria 1000 is for English. For the list of language 
criteria
    # IDs, see:
    # 
https://developers.google.com/google-ads/api/reference/data/codes-formats#languages
    request.language = googleads_service.language_constant_path("1000")

    response = 
keyword_plan_idea_service.generate_keyword_historical_metrics(
        request=request
    )

    for result in response.results:
        metrics = result.keyword_metrics
        # These metrics include those for both the search query and any 
variants
        # included in the response.
        print(
            f"The search query '{result.text}' (and the following variants: 
"
            f"'{result.close_variants if result.close_variants else 
'None'}'), "
            "generated the following historical metrics:\n"
        )

        # Approximate number of monthly searches on this query averaged for 
the
        # past 12 months.
        print(f"\tApproximate monthly searches: 
{metrics.avg_monthly_searches}")

        # The competition level for this search query.
        print(f"\tCompetition level: {metrics.competition}")

        # The competition index for the query in the range [0, 100]. This 
shows
        # how competitive ad placement is for a keyword. The level of
        # competition from 0-100 is determined by the number of ad slots 
filled
        # divided by the total number of ad slots available. If not enough 
data
        # is available, undef will be returned.
        print(f"\tCompetition index: {metrics.competition_index}")

        # Top of page bid low range (20th percentile) in micros for the 
keyword.
        print(
            f"\tTop of page bid low range: 
{metrics.low_top_of_page_bid_micros}"
        )

        # Top of page bid high range (80th percentile) in micros for the
        # keyword.
        print(
            "\tTop of page bid high range: "
            f"{metrics.high_top_of_page_bid_micros}"
        )

        # Approximate number of searches on this query for the past twelve
        # months.
        for month in metrics.monthly_search_volumes:
            print(
                f"\tApproximately {month.monthly_searches} searches in "
                f"{month.month.name}, {month.year}"
            )


and when I  try to run function:
generate_historical_metrics(client, customer_id)
it goes with that error:
--------------------------------------------------------------------------- 
AttributeError Traceback (most recent call last) Cell In[48], line 1 ----> 1 
generate_historical_metrics(client, customer_id) Cell In[30], line 12, in 
generate_historical_metrics(client, customer_id) 10 request = client.
get_type("GenerateKeywordHistoricalMetricsRequest") 11 request.customer_id = 
customer_id ---> 12 request.keywords = ["mars cruise"] 13 # Geo target 
constant 2840 is for USA. 14 request.geo_target_constants.append( 15 
googleads_service.geo_target_constant_path("2840") 16 ) AttributeError: 
Assignment not allowed to message, map, or repeated field "keywords" in 
protocol message object. 

I'm stuck here and don't know what to do next. 

I'll appriciate your help very much

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/f9244560-a1ab-4e86-97dc-f701749d2762n%40googlegroups.com.
  • Go... Maciek eF
    • ... Maciek eF
      • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to