Posts tagged with google-ads-api

I want to use Google Ads API with service account I managed to create a session using this Java code configuration:

ClassLoader classLoader = this.getClass().getClassLoader();         File configFile = new File(classLoader.getResource("ads.properties").getFile());         GoogleAdsClient googleAdsClient = GoogleAdsClient.newBuilder()                 .fromEnvironment()                 .fromPropertiesFile(configFile)                 .build();         GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient(); 

I want to use this connection to make a request using this code:

AdWordsSession session = null;         try {             // Generate a refreshable OAuth2 credential.             Credential oAuth2Credential = new OfflineCredentials.Builder()                             .forApi(Api.ADWORDS)                             .fromFile()                             .build()                             .generateCredential();             // Construct an AdWordsSession.             session =                     new AdWordsSession.Builder().fromFile().build();         } catch (ConfigurationLoadException cle) {             System.err.printf(                     "Failed to load configuration from the %s file. Exception: %s%n",                     DEFAULT_CONFIGURATION_FILENAME, cle);             return;         } catch (ValidationException ve) {             System.err.printf(                     "Invalid configuration in the %s file. Exception: %s%n",                     DEFAULT_CONFIGURATION_FILENAME, ve);             return;         } catch (OAuthException oe) {             System.err.printf(                     "Failed to create OAuth credentials. Check OAuth settings in the %s file. "                             + "Exception: %s%n",                     DEFAULT_CONFIGURATION_FILENAME, oe);             return;         }         AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();         try {             runExample(adWordsServices, session);         } catch (ApiException apiException) {             System.err.println("Request failed due to ApiException. Underlying ApiErrors:");             if (apiException.getErrors() != null) {                 int i = 0;                 for (ApiError apiError : apiException.getErrors()) {                     System.err.printf("  Error %d: %s%n", i++, apiError);                 }             }         } catch (RemoteException re) {             System.err.printf(                     "Request failed unexpectedly due to RemoteException: %s%n", re);         } 

AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException { // Get the TrafficEstimatorService. TrafficEstimatorServiceInterface trafficEstimatorService = adWordsServices.get(session, TrafficEstimatorServiceInterface.class);

Full source: https://developers.google.com/adwords/api/docs/samples/java/basic-operations

Do you know how I can use service account into the above code?

Since we updated the Google Ads API from version 3 to 6 we get the error message "Fail to push the limit".

This happens if we try to link the Manager Account to the client.

return (new GoogleAdsClientBuilder())     ->fromFile()     ->withOAuth2Credential($oAuth2Credential)     ->withLoginCustomerId($loginCustomerId)     ->build(); 

Is there any way to increase the limit?

I'm a back end developer, sometimes a little fronted, but not a SEO related expert at all. Now I have to make a full website from top to bottom and I'm stuck with the Google stuff. First I created a Google Analytics profile, I got the srcipt that I needed to hardcode to all my site.

    <script async src="https://www.googletagmanager.com/gtag/js?id=G-MEASUREMENT_ID></script>     <script>       window.dataLayer = window.dataLayer || [];       function gtag(){dataLayer.push(arguments);}       gtag('js', new Date());       gtag('config', 'G-MEASUREMENT_ID');     </script> 

However, a little while later, I started to use Google Ads and it recommended to connect my Analytics page to the Ads page, so I connected them and I got another code that I needed to insert.

The code snippet is almost the same, except the two MEASUREMENT_ID, because now I got a UA-MEASUREMENT_ID.

So, do I have to use both snippets, or just one? If so, which MEASUREMENT_ID should I use? Or am I screwed up something?

Thanks all the help

I'm trying to display a bar chart that shows the performance of a Google ad between the 1st of March to the 31st of March. Each bar indicates a day in that range.

At the moment my query looks like

SELECT    ad_group_ad.ad.id,   ad_group_ad.ad.name,   metrics.average_cost FROM    ad_group_ad WHERE   segments.date BETWEEN '2021-03-01' AND '2021-03-31' AND ad_group_ad.status = 'ENABLED' 

The data I get back are totals within the range. I need the totals of each day within the range. Is there a way to get this information in one request?