Posts under category google-ads-api

Google Ads API recently discontinued an old version - https://ads-developers.googleblog.com/2021/04/upgrade-to-google-ads-api-from-adwords.html.

That being said I am trying to adjust my query to new api standards, and getting the strangest error "unexpected input DURING" -- more detail below. It would seem to be correct per this doc:https://developers.google.com/google-ads/api/docs/samples/get-hotel-ads-performance

Note the use of "DURING" in the example SQL query in the doc above.

Below is my error message and further below is script:

ERROR:

SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428 Request made: ClientCustomerId:, Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId:, IsFault: True, FaultMessage:  Error in query: unexpected input DURING. 

script:

import sys, json, io, gzip, sys, os from googleads import adwords import pandas as pd import numpy as np def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):   ga_service = client.get_service("GoogleAdsService")   search_request=client.get_type("SearchGoogleAdsStreamRequest")   search_request.customer_id = customer_id   query = f"SELECT {', '.join(str(x) for x in fields)} FROM {str(report_type[0])} WHERE Status IN {*statuses,} DURING {date_range}"      # query = "SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428"                 print(query)   search_request.query = query      stream = ga_service.search_stream(search_request)      for batch in stream:     for row in batch.results:       print(row)         return 1 

Really sorry if this is the basic question.

I have been searching for two days to find the documentation/sample function to use in apps script that fetches google ads accounts, reports, etc. what I have found all, is the documentation for languages like PHP, python, c, etc and they are giving me tough time understanding them. I know integrating google ads in google sheets is possible as google itself has published an add-on to fetch the reports but can't find any hint either in this platform or in the official documentation. any help will be highly appreciated.

Note: I am seeking help for integrating google ads in google sheets through apps script not ads script. I know there are functions available for ads script even in the documentation but none I found for apps script to the best of my research.

Thanks.

I'm trying to use Google Ads API using service account.
The following works:

from google.ads.googleads.client import GoogleAdsClient from google.oauth2.service_account import Credentials as ServiceAccountCreds oauth2_client = ServiceAccountCreds.from_service_account_file(     filename=key_file, subject=developer_account,     scopes=["https://www.googleapis.com/auth/adwords"] ) google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=oauth2_client,                                     developer_token=self.developer_token) self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9") self.ga_serice.search_stream(customer_id=self.client_customer_id, query =  query) 

I want to to do following with Identity Workload Federation(w/o key):

from google.auth import aws as google_auth_aws from google.ads.googleads.client import GoogleAdsClient credentials = google_auth_aws.Credentials.from_info(json_config_info)  # from workload identity federation credentials = credentials.with_scopes(["https://www.googleapis.com/auth/adwords"]) credentials = credentials.with_subject(self.developer_account) # Build the service object. self.google_ads_client = GoogleAdsClient(login_customer_id=self.login_customer_id, credentials=credentials,                                     developer_token=self.developer_token) self.ga_service = self.google_ads_client.get_service("GoogleAdsService", version="v9") self.ga_service.search_stream(customer_id =self.client_customer_id, query =  self.query) 

Which throws error: ERROR:'Credentials' object has no attribute 'with_subject'.

We are trying to implement the Mediation Test Suite but, we are getting the following error message:

Undefined symbols for architecture arm64: "_kGADSimulatorID", referenced from: _GMTSMediationRequest in GoogleMobileAdsMediationTestSuite(GMTSMediationHelper.o)
"_kGADAdSizeBanner", referenced from: -[GMTSBannerAdLoader initWithAdUnitId:rootViewController:] in GoogleMobileAdsMediationTestSuite(GMTSBannerAdLoader.o)
"_kGADAdLoaderAdTypeNative", referenced from: -[GMTSNativeAdLoader initWithAdUnitId:rootViewController:] in GoogleMobileAdsMediationTestSuite(GMTSNativeAdLoader.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've tried to write an ads-script that returns all the child accounts which had zero impression in the latest available hour (3 hours ago)

However the script returns false negative results. Meaning there was an account with zero impressions, but the script flagged it as non-zero.

What am I missing?

function main() {   Logger.log("now.getHours(); = "+new Date().getHours());   var past = new Date(new Date().getTime() - HOURS_BACK * 3600 * 1000);   var pastHour = past.getHours();   var pastDateStr = getDateStringInTimeZone(past, 'yyyy-MM-dd');   query = "SELECT customer.id, metrics.impressions, segments.hour FROM customer WHERE metrics.impressions = 0 AND segments.hour = " + pastHour + " AND segments.date = '" + pastDateStr + "'";   Logger.log("query " + query);   updateAccountsInParallel(); } function updateAccountsInParallel() {   // You can use this approach when you have a large amount of processing   // to do in each of your client accounts.   // Select the accounts to be processed. You can process up to 50 accounts.   var accountSelector = AdsManagerApp.accounts();   // Process the account in parallel. The callback method is optional.   accountSelector.executeInParallel('processAccount', 'allFinished', query); } /**  * Process one account at a time. This method is called by the executeInParallel  * method call in updateAccountsInParallel function for every account that  * it processes.  */ function processAccount(query) {   // executeInParallel will automatically switch context to the account being   // processed, so all calls to AdsApp will apply to the selected account.   var customerId = AdsApp.currentAccount();   if (excludedAccountIds.includes(customerId)) return null;   var currentZeroImpressionRows = AdsApp.report(query, { apiVersion: 'v10' });   var rows = currentZeroImpressionRows.rows();   var accounts = [];   while (rows.hasNext()) {     var row = rows.next();     Logger.log(JSON.stringify(row));     accounts = accounts.push(row["customer.id"] + " " + row["customer.descriptive_name"]);   }     // Optional: return a string value. If you have a more complex JavaScript   // object to return from this method, use JSON.stringify(value). This value   // will be passed on to the callback method, if specified, in the   // executeInParallel method call.   return accounts.length > 0 ? account.getCustomerId() + " " + account.getName() : null; } /**  * Post-process the results from processAccount. This method will be called  * once all the accounts have been processed by the executeInParallel method  * call.  *  * @param {Array.<ExecutionResult>} results An array of ExecutionResult objects,  * one for each account that was processed by the executeInParallel method.  */ function allFinished(results) {   var todayZeroCostAccounts = [];   for (var i = 0; i < results.length; i++) {     // Get the ExecutionResult for an account.     var result = results[i];     //Logger.log('Customer ID: %s; status = %s.', result.getCustomerId(),     //  result.getStatus());     // Check the execution status. This can be one of ERROR, OK, or TIMEOUT.     if (result.getStatus() == 'ERROR') {       Logger.log("-- Failed with error: '%s'.", result.getError());     } else if (result.getStatus() == 'OK') {       // This is the value you returned from processAccount method. If you       // used JSON.stringify(value) in processAccount, you can use       // JSON.parse(text) to reconstruct the JavaScript object.       var retval = result.getReturnValue();       if (retval != null) {         Logger.log('%s had 0 impressions in that hour.', result.getCustomerId());         todayZeroCostAccounts.push(retval);       }       else       {        Logger.log('%s had positive impressions in that hour.', result.getCustomerId());       }            } else {       // Handle timeouts here.     }   } }