Posts under category google-ads-api

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?

I'm doing azure function which should regularly get ad reports from Google Ads API and save it to CSV. Copying code from Google documentation left me with this

public static void Run([TimerTrigger("0 22 12 * * *")] TimerInfo myTimer, ILogger log)     {         log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");         RunRequest(new GoogleAdsClient(new GoogleAdsConfig() {              DeveloperToken = "/*token*/",             OAuth2Mode = OAuth2Flow.SERVICE_ACCOUNT,             OAuth2PrnEmail = "/*service account email*/",             OAuth2SecretsJsonPath = "/*service account json*/"         }), "/*client id*/", log);     } public static void RunRequest(GoogleAdsClient client, string customerId, ILogger log)     {         // Get the GoogleAdsService.         GoogleAdsServiceClient googleAdsService = client.GetService(             Services.V5.GoogleAdsService);         // Create the query.         string query = @"/*request*/";         try         {             // Issue a search request.             googleAdsService.SearchStream(customerId, query,                 delegate (SearchGoogleAdsStreamResponse resp)                 {                     using var writer = new StreamWriter($"reports\\report{DateTime.Now}.csv");                     using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);                     csv.WriteRecords(Report.BuildReports(resp.Results));                 }             );         }         catch (GoogleAdsException e)         {             log.LogInformation("Failure:");             log.LogInformation($"Message: {e.Message}");             log.LogInformation($"Failure: {e.Failure}");             log.LogInformation($"Request ID: {e.RequestId}");             throw;         }     } 

Executing this code gives me an exception with this content:

"Status(StatusCode="Unauthenticated", Detail="Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."

As I understand I don't need OAuth2 access token when using service account. How to fix this problem, what am I missing?