Hi
Could someone help me to code this AWQL query using Python.
I want to add a variable containing a list.
So this works - AND KeywordTextMatchingQuery - IN ['keyword 1', 'keyword 2']
And if a single keyword is a variable, then this works - AND KeywordTextMatchingQuery = " +"'"+ keyword_variable_example +"'"+ "
But if the list is a variable I can’t concatenate it.
I found this (https://groups.google.com/g/adwords-api/c/E7eF1AZc8Mw/m/nqSX9AB0BwAJ) but can’t make it work with the grammer/style that I’m using.
Can anyone help?
|
||||||
keyword_list = ["keyword1", "keyword2", "keyword3"]keyword_list_as_string = ', '.join(str(e) for e in keyword_list)
#This should work with the AdWords API Python library:query = ('SELECT Id, Criteria, AdGroupName FROM KEYWORDS_PERFORMANCE_REPORT ' 'WHERE somecondition ' 'AND KeywordTextMatchingQuery IN [{}]'.format(keyword_list_as_string) )
#And this is a Python example that does work with the Google Ads API Python library:
shared_set_ids = [1234, 5678, 2345] shared_set_ids_as_string = ', '.join(str(e) for e in shared_set_ids) query = ('SELECT ' 'shared_criterion.criterion_id, ' 'shared_criterion.keyword.match_type, ' 'shared_criterion.keyword.text, ' 'shared_criterion.type, ' 'FROM shared_criterion ' 'WHERE shared_set.id IN ({}) ' 'AND shared_set.status = ENABLED ' 'AND shared_set.type = NEGATIVE_KEYWORDS'.format(shared_set_ids_as_string) )"SELECT Id, Criteria, AdGroupName FROM SEARCH_QUERY_PERFORMANCE_REPORT WHERE somecondition AND KeywordTextMatchingQuery IN [{}]".format(keyword_list_as_string)
report_query = ("SELECT KeywordTextMatchingQuery, Clicks FROM SEARCH_QUERY_PERFORMANCE_REPORT WHERE KeywordTextMatchingQuery IN [{}]".format(list_of_keywords))list_of_keywords_counted = ['keyword 1', 'keyword 2', '+keyword 3']
list_of_keywords = str(list_of_keywords_counted)[1:-1]
#this will result in a string, where the keywords are enclosed in single quotes:
#'keyword 1', 'keyword 2', '+keyword 3'
report_query = ("SELECT KeywordTextMatchingQuery, Clicks FROM SEARCH_QUERY_PERFORMANCE_REPORT WHERE KeywordTextMatchingQuery IN [{}]".format(list_of_keywords))