Hello,
When I am running below code in mu local it is running fine and returning proper result but when I am running same code in Airflow it is giving me error for version.
Airflow Error :-
b"googleads.errors.GoogleAdsValueError: Unrecognized version for the AdWords API. Given: v201809 Supported: ['v201609', 'v201702', 'v201705', 'v201708']\n"
Code:-
#!/usr/bin/env python
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
http://www.apache.org/licenses/LICENSE-2.0#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This example gets all campaigns.
To add a campaign, run add_campaign.py.
The LoadFromStorage method is pulling credentials and properties from a
"googleads.yaml" file. By default, it looks for this file in your home
directory. For more information, see the "Caching authentication information"
section of our README.
"""
from googleads import adwords
PAGE_SIZE = 100
def main(metro_criteria_id):
# Initialize appropriate service.
location_criterion_service = adwords_client.GetService(
'LocationCriterionService', version='v201809')
location_names_metro = metro_criteria_id
# Create the selector.
selector = {
'fields': ['Id', 'LocationName', 'DisplayType', 'CanonicalName',
'ParentLocations', 'Reach', 'TargetingStatus'],
'predicates': [{
'field': 'Id',
'operator': 'IN',
'values': location_names_metro
}, {
'field': 'Locale',
'operator': 'EQUALS',
'values': ['en']
}]
}
# Make the get request.
location_criteria = location_criterion_service.get(selector)
print(f'location criteria....{location_criteria}')
if __name__ == '__main__':
adwords_credentials = gen_api_credentials()
global adwords_client
adwords_client = adwords.AdWordsClient.LoadFromString(adwords_credentials)
print('start')
main(20652)
Result:
start
location criteria....[{
'location': {
'id': 20652,
'type': None,
'Criterion.Type': 'Location',
'locationName': 'Nara',
'displayType': 'Prefecture',
'targetingStatus': 'ACTIVE',
'parentLocations': [
{
'id': 9073778,
'type': None,
'Criterion.Type': 'Location',
'locationName': 'JP_KINKI',
'displayType': 'DMA Region',
'targetingStatus': 'ACTIVE',
'parentLocations': []
},
{
'id': 2392,
'type': None,
'Criterion.Type': 'Location',
'locationName': 'Japan',
'displayType': 'Country',
'targetingStatus': 'ACTIVE',
'parentLocations': []
}
]
},
'canonicalName': 'Nara,Japan',
'reach': 1230000,
'locale': None,
'searchTerm': None,
'countryCode': None
}]
Process finished with exit code 0