From 875d653d3f648f9c8986308ebf01eb94bda2de8b Mon Sep 17 00:00:00 2001 From: Francisco Blasco Garma Date: Fri, 13 Jan 2023 16:36:11 -0800 Subject: [PATCH] upgrade to Google Ads API v12 and required changes --- README.md | 6 ++- .../create_smart_campaign.cpython-39.pyc | Bin 7705 -> 6489 bytes api/__pycache__/keyword_themes.cpython-39.pyc | Bin 3883 -> 3934 bytes api/create_smart_campaign.py | 47 ++---------------- api/keyword_themes.py | 6 +-- requirements.txt | 2 +- 6 files changed, 14 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index a185663..633dc04 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/api/__pycache__/create_smart_campaign.cpython-39.pyc b/api/__pycache__/create_smart_campaign.cpython-39.pyc index b4093a7b32809134c8c750f108718c6eb44e9f0d..665e6adc7d944e11ad0c5f8eed259dbaffbff067 100644 GIT binary patch delta 1377 zcmZ{kO>7%Q7>0N3#5n#9C5iuHCm{_X361mb#D9qsrwwgd+J+JcZ8wf*YkA_>$$EWg z^lbyJ)B_Td&2Ru!5jIE_+z{r1kPy8h#GN37goMNm4qSRb;+t)#3J6J2KIcew)AriFVd>TCU85m}#SVWtx&ru1+ShQhkn2-bVa6t5lc?_Ho!}%;bU%voz5QSLIEYd%A z#K8segC{Hra6`hdyo8oGByuLhFsvsr?tpjzniG=7gAj*(4r9#2JiCYo9)U27=gctm zA%U41fn<%)!M9EN0xYmgY3bTGdWt@;FVZ1B2q_k=U#57K)mHW3T{@yK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_d&+%d2E5h4o8@XW-7FYEfb`y`1?rnrL zaTLZealAAl2CU20O+H#0BbvBsjhB68AK(M-HPG$xa)B#-ajVn4E(S{%1rjI9K5<>2 z5XY^P)}%EB&po0Cbs1z0hWyoU3zxAmYa)%*Ouh$zq(Vc)u zHz2Dfg3G8h2l2Wf-VMD&G?Ul8yTLQ<)yVVKEtu_rEMs7M+Iuf}qPPIIBR{bn(Qm6< zlhzwz#Cj8KKw69LP0$RHGiBtCibgT2|LkBqCL&_&(0E)##W;*_T1%y$i%~Hq#?yY8 z{eeYXG>LfekjaENCMJ~09WaTDiL_4{47ih!?pfIY9uj& z{Ze6F#Ts~Bfjwkcfp1F?YQ7<6-`7Y?bb}mu9+Z{u1h=w)+?3B`RMz(voS^}YukAEE z{X5d!1k&F9HE4{9g!K;Cjl=y{rTb;g>Vi?c>ILQ=SUT{sFzwEP@`RYP9s)f191d&f z(VR64xjvJ3%K)_wcOJB+#JsiszV_Uw5^31_(@w+IGoC6DGVT5ANH3c4j)uPIZ-cGG z+NJ1_;y8#(OV+d>QKF{`4$tQ(gF}v;*!y?rV}yI*K;)*K#)Zwg@1MP|!~gXmy7y)D zDnfYgKTThuu-dLH0-pE2ZT=8-osoggO3^39IVsLdal!j-i`A%-IW5O0z3*H4(1`bX zYx}7rOjIISIE5g(zG=Wm#G=%ZZoO3NqvmEgdQA%X(qOIL-&*r%!dq%Pj;6egw#Cjk zOjnu@4sLF+H02Ik_P%NBYsAv#mK1lq|Fzvl3tpl<(Ro)+tbkZ+G>D#N`NF1d5O&Y| zp#2tF_5RTwkKG5f(xN^AAS<5HX_n@w%~@31D$yiWA}MwH>5lwDnA!WR&tVQ0hGzX;+0 diff --git a/api/__pycache__/keyword_themes.cpython-39.pyc b/api/__pycache__/keyword_themes.cpython-39.pyc index e939015d041e81b987721225bf93e9ba22da97cc..4dd941cc945a5d79c28c714029edc94f99c5d616 100644 GIT binary patch delta 647 zcma)&%WD%+6voe)2gb1zTT4@II!We{cdTuFZHfrG5!|^5ZIw_u#r75>O$Q|5Tw4%a zSs0mR3Cw`FQ3RR2;8y$_T=|G4EKKAb3X3^+rRP`6u zfLzw%8U$t5#S@e@s>PKALS^8M76My1LLoN_wYeEvxS=xqh>-p4@}e*5{7RiJ#^?M> zg3=-+t5+q3_w%IkeksuX!Yh6^(8Y^6q)#6cImbrK3Pp_QmQ;-cR--jo!Cn^5r zZ~W!A|C?VOIA{F6buyvwOW8|Zh+<7Y%JQhgcV~GL&b1DGWtm5M;825ErkN$1o}EpP ztDk~K+$2uRSt?z41R4abP#f+d$R@(*m{Zx*6zx;+9o9~KH36~2CwHt*CeReu#4_J} z_pxlT*`tcWq2Ca+|1Z6r#6AA*~uZVkd21uyJ-{X8%Pm*xh-y)7yUDKMc0| ZLHcmYK&(Vv^F3m8Ctt+*^m2X{e*tz0rnUe8 delta 624 zcmbV}&ubGw6vyA2*;R?%SP;dg+1>1Bliei#X#I8SL8zDF(L)dsX<4w&A&|J2gg2%j z6fcE^&{K)*UW(vJ_TpdQ*}uTQpnpW)RPdm9afabL^M3I@Z+?1TJZIN&YQXE;@&4Yy zS4ZHD0l$oCo6oy_3m})X?^T3>m>=qZ0@c(Zg@s!JYpYnHutWs5uj=+&&=IvMN*h~1 zA?x}UWFBkt2z7@#ge)C+{`M^)l4!llg#D#a~2l~F&5LehVUGCCcWI6 z?jh&|VRpb+0VS$`0%^!PC~lXa?(nO6Rbad1REwZZPrQeL=wYBRSc zf~}kCK1bcueU9o|yaJjZG^<{(_Vnc%O`FzqC5EcO*Wpeq4Ep g)ppHB98^131FZB)4bfYCbWRtOdIN7&&+6Cl9CEgui2wiq diff --git a/api/create_smart_campaign.py b/api/create_smart_campaign.py index a394bca..e6ec2c0 100644 --- a/api/create_smart_campaign.py +++ b/api/create_smart_campaign.py @@ -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, @@ -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. """ @@ -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 diff --git a/api/keyword_themes.py b/api/keyword_themes.py index 8ddc918..f28d15a 100644 --- a/api/keyword_themes.py +++ b/api/keyword_themes.py @@ -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 @@ -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 ''' diff --git a/requirements.txt b/requirements.txt index 6e2008f..b7c59e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file