LocationCriterionService not working in Airflow

46 views
Skip to first unread message

Jayant Meshram

unread,
Jan 3, 2022, 10:52:05 AM1/3/22
to AdWords API and Google Ads API Forum
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

Google Ads API Forum Advisor

unread,
Jan 3, 2022, 9:23:33 PM1/3/22
to jayant....@kpipartners.com, adwor...@googlegroups.com
Hi Jayant,

Thank you for reaching out to our API support team.

You may note that our team can only provide support for AdWords / Google Ads API related concerns. Since you mentioned that the issue is being encountered when the API request is made through Airflow, then our API support team may not be able to troubleshoot as we do not have visibility to the inner workings of Airflow.

You may instead reach out to their support team for further guidance.

In the API's perspective, our team can investigate your request for any issues if the said issues were encountered when using the API directly, and not through other platforms. Our team would then require the complete SOAP request and response logs, with the requestId.

In the event that you are still encountering the issue without using Airflow, you may send to our team the above details via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Lastly, please note that the AdWords API is deprecated and will be sunset on April 27, 2022. We strongly recommend that you migrate to the Google Ads API as soon as possible.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2TnLTC:ref
Reply all
Reply to author
Forward
0 new messages