Posts tagged with python-3.x

I have followed the guide below to obtain a Google Ads API refresh token for my application.

https://github.com/googleads/googleads-python-lib/wiki/API-access-on-behalf-of-your-clients-(web-flow)

Using the script below, everything worked, but the response only had an access token, while the refresh token was None.

from googleads import oauth2 import google.oauth2.credentials import google_auth_oauthlib.flow # Initialize the flow using the client ID and secret downloaded earlier. # Note: You can use the GetAPIScope helper function to retrieve the # appropriate scope for AdWords or Ad Manager. flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(     'client_secret.json',     [oauth2.GetAPIScope('adwords')]) # Indicate where the API server will redirect the user after the user completes # the authorization flow. The redirect URI is required. flow.redirect_uri = 'https://www.example.com' # Generate URL for request to Google's OAuth 2.0 server. # Use kwargs to set optional request parameters. authorization_url, state = flow.authorization_url(     # Enable offline access so that you can refresh an access token without     # re-prompting the user for permission. Recommended for web server apps.     access_type='offline',     # Enable incremental authorization. Recommended as a best practice.     include_granted_scopes='true',     # approval_prompt='force' ) print("\n" + authorization_url) print("\nVisit the above URL and grant access. You will be redirected. Get the 'code' from the query params of the redirect URL.") auth_code = input('\nCode: ').strip() flow.fetch_token(code=auth_code) credentials = flow.credentials print(credentials.__dict__) 

I have a daily Python script that pulls data from the Google Ads API. I had the v20.0.0 of the google ads library installed. On October 28, it started failing with this error:

Error with message " Version v2 is deprecated. Requests to this version will be blocked." 

I assume this is because of this setup line:

ga_service = client.get_service('GoogleAdsService', version='v2') 

But when I change that to v3 (just a guess, since the error message doesn't tell me what versions are accepted), I get this when I run the script:

ValueError: Specified Google Ads API version "v3" does not exist. Valid API versions are: "v2", "v1" 

I ran pip install --upgrade googleads, which got me up to v25.0.0, but still got the same errors. I then uninstalled and re-installed googleads, but still get the same errors.

I haven't been able to find a migration guide in Google's documentation. Does anyone know how to update the package and script to get it running again?

Before trying with the production data, I'm going to try using the Google Ads API with a test account. I have already set up that and I have the Customer ID, manager account customer ID, and the developer token. The next step in the docs states I need to set up the .yaml file which has the follwing fields:

developer_token: INSERT_DEVELOPER_TOKEN_HERE client_id: INSERT_OAUTH2_CLIENT_ID_HERE client_secret: INSERT_OAUTH2_CLIENT_SECRET_HERE refresh_token: INSERT_REFRESH_TOKEN_HERE login_customer_id: INSERT_LOGIN_CUSTOMER_ID_HERE 

My question here is what is the client_id and client_secret? I know that the refresh_token needs to set up like this in their docs: https://developers.google.com/google-ads/api/docs/client-libs/python/oauth-installed

Is the client_id and secret_id the OAuth 2.0 Client IDs setup in the my personal account in the developer console?

*I am using the Google Ads API and NOT the AdWords API

I'm making a script buildt with code from the google ads api. In this script I'm trying to make a new account, and for that to happen, i need to select which manager account the script should be under. That is done with this code:

parser = argparse.ArgumentParser(description=('Creates a new client under the given manager.')) # The following argument(s) should be provided to run the example. parser.add_argument('-m', '--manager_customer_id', type=str,                     required=True, help='A Google Ads customer ID for the '                     'manager account under which the new customer will '                     'be created.') args = parser.parse_args() 

So when i run the script, i type in python new_acc.py xxx-xxx-xxxx and hit enter, and then i get the following error:

usage: new_acc.py [-h] -m MANAGER_CUSTOMER_ID new_acc.py: error: the following arguments are required: -m/--manager_customer_id 

I have also tried to add the manager_customer_id in the .yaml file.

I am currently importing conversions (Store Sales Direct Conversion) into Google Ads using UI on every month. I am creating data to import to Google Ads in CSV format and then upload it using UI. Current Method: Google Ads > Conversions > Uploads

I need to automate this process using Google Ads API and its Python module. How can I get this done? What are the steps required to complete this job?