Posts tagged with python

I am working with Google Ads and taking look in the documentation to see how to code a campaign.

from google.ads.google_ads.client import GoogleAdsClient def create_campaign(google_ads_client, campaign_name, budget_micros):     campaign_operation = google_ads_client.service.campaign.create(         customer_id="YOUR_CUSTOMER_ID",         campaign={             "name": campaign_name,             "advertising_channel_type": "SEARCH",             "status": "PAUSED",             "manual_cpc": {                 "enhanced_cpc_enabled": True             },             "campaign_budget": {                 "amount_micros": budget_micros             },             "network_settings": {                 "target_google_search": True,                 "target_search_network": True,                 "target_content_network": False,                 "target_partner_search_network": False             }         }     )     # Execute the campaign operation     response = campaign_operation.execute()     # Print the created campaign's resource name     print("Created campaign with resource name: " + response.resource_name) # Set up the Google Ads API client google_ads_client = GoogleAdsClient.load_from_storage() # Define the campaign details campaign_name = "My Campaign" budget_micros = 5.000000   

The error raised with macro budget and I don't know what is this, I tried set the number based on what documentation suggesting and still don't understand it

I'm using OAuth2 flow to get access to a Google Ads Account. My application runs in a flask server, so I can get the authorization code from the OAuth2 flow using the the requestvariable in the flask context. First, I get the permission screen url, that redirects to "/google_ads/authorized" flask route.

auth_url = 'https://accounts.google.com/o/oauth2/auth' client_id = os.environ['CLIENT_ID'] client_secret = os.environ['CLIENT_SECRET'] redirect_uri = os.environ['REDIRECT_URI'] scope = 'https://www.googleapis.com/auth/adwords' 

In the redirected flask route I'm making a request to exchange the authorization code by the access token and refresh token.

token_url = 'https://accounts.google.com/o/oauth2/token' payload = {  "code": request.args['code'],  "client_id": client_id,  "client_secret": client_secret,  "redirect_uri": redirect_uri,  "grant_type": "authorization_code" } req = requests.post(url=token_url, data=json.dumps(payload) res = req.json() credentials = {  'access_token': res['access_token'],   'refresh_token': res['refresh_token'],   'client_id': client_id,  'client_secret': client_secret,   'expiry': '2023-06-12T18:01:59',   'scopes': ['https://www.googleapis.com/auth/adwords'] } 

Finally, I use the credentials dict to build a Credentials object, that is passed with the developer token as an argument to instantiate the GoogleAdsClient,

from google.oauth2.credentials import Credentials from google.ads.googleads.client import GoogleAdsClient developer_token = os.environ['DEVELOPER_TOKEN'] credentials=Credentials.from_authorized_user_info(creds) client = GoogleAdsClient(credentials=credentials, developer_token=developer_token) customer_service = client.get_service("CustomerService") customer_service.list_accessible_customers() 

When I try to make a request and list the available customers in the account, using customer_service.list_accessible_customers(), I got the following error:

{  "error": {    "code": 403,    "message": "The caller does not have permission",    "status": "PERMISSION_DENIED",    "details": [      {       "@type": "type.googleapis.com/google.ads.googleads.v14.errors.GoogleAdsFailure",       "errors": [      {        "errorCode": {           "authorizationError": "DEVELOPER_TOKEN_PROHIBITED"        },        "message": "Developer token is not allowed with project '685646918301'."          }        ],        "requestId": "hYMHcD_FbdI0vwYeKRrAbw"       }     ]   } } 

This method is the same method that I'm using to authenticate Google Analytics API requests. I already tried using the flow lib and I got the same error.

I have a customer match list id that I want to remove all data from it at once (without deleting it) i'm using the Python client library, it has examples, however for this specific case:

https://developers.google.com/google-ads/api/docs/remarketing/audience-types/customer-match#remove_all_data_from_the_list_at_once

I'm not understanding how to write a python code to achieve it, I appreciate the help!

I have a code that give me suggestion of keywords from google ads api.

in this code I have a section that select language with language id but in new version of Google Ads API (V13) it's deprecated and removed.

language_rn = client.get_service(         "LanguageConstantService"     ).language_constant_path(language_id) 

What is the alternative of LanguageConstantService Now? How can I set Language in my request?

I find my code from link below: https://www.danielherediamejias.com/python-keyword-planner-google-ads-api/


The Error is:

ValueError: Specified service LanguageConstantService does not exist in Google Ads API v13.

I am utilizing the python client library for the Google Ads API. Alls has been working as expected and all of a sudden began running extremely slow when running locally on my Mac. Ran the cProfile tool and found that this 'next_event' method from gRPC has started taking between 8-10secs per call.

Even basic usage of the API (i.e. GAQL to pull in campaign names) returns the same latency issue.

ncalls  tottime  percall  cumtime  percall filename:lineno(function)         1    8.123    8.123    8.126    8.126 {method 'next_event' of 'grpc._cython.cygrpc.SegregatedCall' objects} 

Have tried various versions of Python and the google-ads and gRPC packages. Others have ran this same code from the same repo/branch on their machines and do not experience this issue so I am trying to determine what about my environment/Mac is causing this issue.