Posts tagged with google-ads-api

I'm getting to Google Ads scripts. I managed to execute this script that pauses a specific campaign but I couldn't apply this to multiple campaigns. Here is what I tried, but it only pauses the first campaign in ("Name IN ['test1', 'test2']"). Could someone help me to achieve this?

function main () {   var campaignIterator = AdsApp.campaigns()     .withCondition("Name IN ['test1', 'test2']").get();   if (campaignIterator.hasNext()) {     var campaign = campaignIterator.next();     campaign.pause();   } }

This question is for those who are working with Google AdWords.

In Google AdWords, we have these account permissions

Is there any way to check if a user has read-only, standard or admin permissions via API? In ManagedCustomerService we have canManageClients, is this the admin? What about ready only and standard permissions?

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?