Skip to content

Commit

Permalink
upgrade to Google Ads API v12 and required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fblascogarma committed Jan 14, 2023
1 parent 8c0b41e commit 875d653
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 47 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ If this project helped you, please **give it a star**.

Give us your feedback [here](https://forms.gle/khdLQ7gDrU8i4p2j9) please. Any feature requests, bugs, satisfaction with the project, or others.

Thank you!
Testimonial from a company who used this project:
>"We looked at your app in great detail and learnt a lot from it.
Your app worked like a charm and gave us a good sense of various components involved.
The [document](https://docs.google.com/document/d/10WyzDUNZTVHhenWgCopf3YyaRDsyoavc7aHuOAMJF6Y/edit?usp=sharing) you provided was also very helpful.
Thank you fo putting this together."

# Assumptions & Prerequisites

Expand Down
Binary file modified api/__pycache__/create_smart_campaign.cpython-39.pyc
Binary file not shown.
Binary file modified api/__pycache__/keyword_themes.cpython-39.pyc
Binary file not shown.
47 changes: 5 additions & 42 deletions api/create_smart_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,6 @@

from .models import KeywordThemesRecommendations

def _convert_business_location_id(business_location_id):
"""Converts a business location ID to a signed 64 bit integer, if necessary.
A Business Profile location ID may be outside of the range for a signed
64 bit int (>= 2^63), which will cause an error to be raised when it's set
to the business_location_id field on a SmartCampaignSuggestionInfo
or SmartCampaignSetting instance. If that's the case this method will
convert it to a signed 64 bit integer for use in the request.
The number will only be converted if it's a 64 bit integer and outside of
the range for a signed 64 bit integer. If it's greater than 64 bits an error
will be raised, and if it's within range for a signed 64 bit integer it
will be returned as-is.
Args:
business_location_id: the ID of a Business Profile location.
Returns:
a business location ID as a signed 64 bit integer.
"""
_64_BIT_RANGE_CEILING = 2 ** 64
_SIGNED_64_BIT_RANGE_CEILING = 2 ** 63
if business_location_id >= _64_BIT_RANGE_CEILING:
# If the business location ID is outside of 64 bit range it can't
# be converted to a signed 64 bit integer and is invalid.
raise ValueError(
"The given business_location_id is outside of the range for "
"a 64 bit integer."
)
elif business_location_id >= _SIGNED_64_BIT_RANGE_CEILING:
# If the business location ID is 64 bits but outside of the range
# of a signed 64 bit integer we convert it to its two's complement
# and pass that to the API.
return ctypes.c_int64(business_location_id).value
else:
return business_location_id


def create_smart(
refresh_token, customer_id, display_name, geo_target_names,
Expand Down Expand Up @@ -264,8 +227,8 @@ def create_smart(
Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
business_location_id: the ID of a Google My Business location.
business_name: the name of a Google My Business.
business_location_id: the ID of a Google Business Profile location.
business_name: the name of a Google Business Profile.
Returns:
a MutateOperation that creates a SmartCampaignSetting.
"""
Expand All @@ -289,9 +252,9 @@ def create_smart(
# It's required that either a business location ID or a business name is
# added to the SmartCampaignSetting.
if len(business_location_id) > 0:
print('setting up business_location_id')
business_location_id = _convert_business_location_id(int(business_location_id))
smart_campaign_setting.business_location_id = business_location_id
print('setting up business_profile_location')
business_location_id = 'locations/'+str((business_location_id))
smart_campaign_setting.business_profile_location = business_location_id
else:
print('no business_location_id so setting up business_name')
smart_campaign_setting.business_name = business_name
Expand Down
6 changes: 3 additions & 3 deletions api/keyword_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ def get_keyword_themes_suggestions(
recommendations = []
for i in keyword_theme_constants:

display_name = i.display_name
kw_theme_constant = i.keyword_theme_constant
display_name = kw_theme_constant.display_name
# send only the display_name to the frontend
# and in title case (fist letter of every word in upper case)
display_name = display_name.title()
recommendations.append(display_name)
resource_name = i.resource_name
resource_name = kw_theme_constant.resource_name
# save display_name and resource_name in model
data_model = {}
data_model["resource_name"] = resource_name
Expand All @@ -181,7 +182,6 @@ def get_keyword_themes_suggestions(
except KeywordThemesRecommendations.DoesNotExist:
serializer.save()

# json.dumps(recommendations)
'''
Here ends the new service to get keyword theme recommendations
'''
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django==3.2.4
django-cors-headers==3.7.0
djangorestframework==3.12.4
google-ads==16.0.0
google-ads==19.0.0
google-api-python-client==2.36.0

0 comments on commit 875d653

Please sign in to comment.