Skip to content

Commit f757b7c

Browse files
authored
Changes for release v0_3.
1 parent b608045 commit f757b7c

529 files changed

Lines changed: 97550 additions & 5207 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
0.3.2 - 2018-08-29
2+
------------------
3+
Added support and examples for Google Ads API v0_3.
4+
5+
- Updated the minimum JRE version to 1.8. This keeps the JRE version consistent
6+
with the AdWords API Java library, where the min JRE changed to 1.8 in version
7+
[3.16.0](https://github.com/googleads/googleads-java-lib/releases/tag/3.16.0).
8+
- Updated GetArtifactMetadata to quote the name param value.
9+
- Added examples showing how to add and get ad group bid modifiers.
10+
- Added an example showing how to create and attach shared keyword sets.
11+
- Added an example showing how to remove shared set criteria.
12+
- Updated hotel ad group bid modifier example with v0_3 criteria changes.
13+
- Added AddCampaignBidModifier example.
14+
115
0.3.1 - 2018-08-08
216
------------------
317

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ This project hosts the Java client library for the Google Ads API.
145145
To ensure that the credentials in that file are valid, run the
146146
[GetCampaigns example](https://github.com/googleads/google-ads-java/tree/master/google-ads-examples/src/main/java/com/google/ads/googleads/examples/basicoperations/GetCampaigns.java),
147147
either via your IDE or from the command line using Maven. This example
148-
requires a `--customerId` parameter where the value is your AdWords
148+
requires a `--customerId` parameter where the value is your Google Ads
149149
account's customer ID without dashes. Here's how you can pass that
150150
information if you are using Maven from the command line.
151151
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.ads.googleads.examples.advancedoperations;
16+
17+
import com.beust.jcommander.Parameter;
18+
import com.google.ads.googleads.examples.utils.ArgumentNames;
19+
import com.google.ads.googleads.examples.utils.CodeSampleParams;
20+
import com.google.ads.googleads.lib.GoogleAdsClient;
21+
import com.google.ads.googleads.lib.GoogleAdsException;
22+
import com.google.ads.googleads.v0.common.DeviceInfo;
23+
import com.google.ads.googleads.v0.enums.DeviceEnum.Device;
24+
import com.google.ads.googleads.v0.errors.GoogleAdsError;
25+
import com.google.ads.googleads.v0.resources.AdGroupBidModifier;
26+
import com.google.ads.googleads.v0.resources.AdGroupName;
27+
import com.google.ads.googleads.v0.services.AdGroupBidModifierOperation;
28+
import com.google.ads.googleads.v0.services.AdGroupBidModifierServiceClient;
29+
import com.google.ads.googleads.v0.services.MutateAdGroupBidModifierResult;
30+
import com.google.ads.googleads.v0.services.MutateAdGroupBidModifiersResponse;
31+
import com.google.common.collect.ImmutableList;
32+
import com.google.protobuf.DoubleValue;
33+
import com.google.protobuf.StringValue;
34+
import java.io.FileNotFoundException;
35+
import java.io.IOException;
36+
37+
/**
38+
* This example demonstrates how to add an ad group bid modifier for mobile devices. To get ad group
39+
* bid modifiers, see advancedoperations/GetAdGroupBidModifiers.java.
40+
*/
41+
public class AddAdGroupBidModifier {
42+
43+
private static class AddAdGroupBidModifierParams extends CodeSampleParams {
44+
45+
@Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
46+
private Long customerId;
47+
48+
@Parameter(names = ArgumentNames.AD_GROUP_ID, required = true)
49+
private Long adGroupId;
50+
51+
/** Specify the bid modifier value here or the default specified below will be used. */
52+
@Parameter(names = ArgumentNames.BID_MODIFIER)
53+
private Double bidModifier = 1.5;
54+
}
55+
56+
public static void main(String[] args) {
57+
AddAdGroupBidModifierParams params = new AddAdGroupBidModifierParams();
58+
if (!params.parseArguments(args)) {
59+
60+
// Either pass the required parameters for this example on the command line, or insert them
61+
// into the code here. See the parameter class definition above for descriptions.
62+
params.customerId = Long.parseLong("INSERT_CUSTOMER_ID_HERE");
63+
params.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
64+
// Optional: To use a different bid modifier value from the default (1.5), uncomment
65+
// the line below and insert the desired bid modifier value.
66+
// params.bidModifier = Double.parseDouble("INSERT_BID_MODIFIER_VALUE_HERE");
67+
}
68+
69+
GoogleAdsClient googleAdsClient;
70+
try {
71+
googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
72+
} catch (FileNotFoundException fnfe) {
73+
System.err.printf(
74+
"Failed to load GoogleAdsClient configuration from file. Exception: %s%n", fnfe);
75+
return;
76+
} catch (IOException ioe) {
77+
System.err.printf("Failed to create GoogleAdsClient. Exception: %s%n", ioe);
78+
return;
79+
}
80+
81+
try {
82+
new AddAdGroupBidModifier()
83+
.runExample(
84+
googleAdsClient, params.customerId, params.adGroupId, params.bidModifier);
85+
} catch (GoogleAdsException gae) {
86+
// GoogleAdsException is the base class for most exceptions thrown by an API request.
87+
// Instances of this exception have a message and a GoogleAdsFailure that contains a
88+
// collection of GoogleAdsErrors that indicate the underlying causes of the
89+
// GoogleAdsException.
90+
System.err.printf(
91+
"Request ID %s failed due to GoogleAdsException. Underlying errors:%n",
92+
gae.getRequestId());
93+
int i = 0;
94+
for (GoogleAdsError googleAdsError : gae.getGoogleAdsFailure().getErrorsList()) {
95+
System.err.printf(" Error %d: %s%n", i++, googleAdsError);
96+
}
97+
}
98+
}
99+
100+
/**
101+
* Runs the example.
102+
*
103+
* @param googleAdsClient the Google Ads API client.
104+
* @param customerId the client customer ID.
105+
* @param adGroupId the ID of the ad group.
106+
* @param bidModifier the bid modifier value to set
107+
* @throws GoogleAdsException if an API request failed with one or more service errors.
108+
*/
109+
private void runExample(
110+
GoogleAdsClient googleAdsClient, long customerId, long adGroupId, double bidModifier) {
111+
112+
// Creates an ad group bid modifier for mobile devices with the specified ad group ID and
113+
// bid modifier value.
114+
AdGroupBidModifier adGroupBidModifier =
115+
AdGroupBidModifier.newBuilder()
116+
.setAdGroup(
117+
StringValue.of(
118+
AdGroupName.format(Long.toString(customerId), Long.toString(adGroupId))))
119+
.setBidModifier(DoubleValue.of(bidModifier))
120+
.setDevice(DeviceInfo.newBuilder().setType(Device.MOBILE))
121+
.build();
122+
123+
// Creates an ad group bid modifier operation for creating an ad group bid modifier.
124+
AdGroupBidModifierOperation adGroupBidModifierOperation =
125+
AdGroupBidModifierOperation.newBuilder().setCreate(adGroupBidModifier).build();
126+
127+
// Issues a mutate request to add the ad group bid modifier.
128+
try (AdGroupBidModifierServiceClient adGroupBidModifierServiceClient =
129+
googleAdsClient.getAdGroupBidModifierServiceClient()) {
130+
MutateAdGroupBidModifiersResponse response =
131+
adGroupBidModifierServiceClient.mutateAdGroupBidModifiers(
132+
Long.toString(customerId), ImmutableList.of(adGroupBidModifierOperation));
133+
134+
System.out.printf("Added %d ad group bid modifiers:%n", response.getResultsCount());
135+
for (MutateAdGroupBidModifierResult mutateAdGroupBidModifierResult :
136+
response.getResultsList()) {
137+
System.out.printf("\t%s%n", mutateAdGroupBidModifierResult.getResourceName());
138+
}
139+
}
140+
}
141+
}

google-ads-examples/src/main/java/com/google/ads/googleads/examples/advancedoperations/AddExpandedTextAdWithUpgradedUrls.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import com.google.ads.googleads.examples.utils.CodeSampleParams;
2020
import com.google.ads.googleads.lib.GoogleAdsClient;
2121
import com.google.ads.googleads.lib.GoogleAdsException;
22-
import com.google.ads.googleads.v0.common.Ad;
2322
import com.google.ads.googleads.v0.common.CustomParameter;
2423
import com.google.ads.googleads.v0.common.ExpandedTextAdInfo;
2524
import com.google.ads.googleads.v0.enums.AdGroupAdStatusEnum.AdGroupAdStatus;
2625
import com.google.ads.googleads.v0.errors.GoogleAdsError;
26+
import com.google.ads.googleads.v0.resources.Ad;
2727
import com.google.ads.googleads.v0.resources.AdGroupAd;
2828
import com.google.ads.googleads.v0.resources.AdGroupName;
2929
import com.google.ads.googleads.v0.services.AdGroupAdOperation;
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.ads.googleads.examples.advancedoperations;
16+
17+
import com.beust.jcommander.Parameter;
18+
import com.google.ads.googleads.examples.utils.ArgumentNames;
19+
import com.google.ads.googleads.examples.utils.CodeSampleParams;
20+
import com.google.ads.googleads.lib.GoogleAdsClient;
21+
import com.google.ads.googleads.lib.GoogleAdsException;
22+
import com.google.ads.googleads.v0.common.KeywordInfo;
23+
import com.google.ads.googleads.v0.enums.KeywordMatchTypeEnum.KeywordMatchType;
24+
import com.google.ads.googleads.v0.enums.SharedSetTypeEnum.SharedSetType;
25+
import com.google.ads.googleads.v0.errors.GoogleAdsError;
26+
import com.google.ads.googleads.v0.resources.CampaignName;
27+
import com.google.ads.googleads.v0.resources.CampaignSharedSet;
28+
import com.google.ads.googleads.v0.resources.SharedCriterion;
29+
import com.google.ads.googleads.v0.resources.SharedSet;
30+
import com.google.ads.googleads.v0.services.CampaignSharedSetOperation;
31+
import com.google.ads.googleads.v0.services.CampaignSharedSetServiceClient;
32+
import com.google.ads.googleads.v0.services.MutateCampaignSharedSetsResponse;
33+
import com.google.ads.googleads.v0.services.MutateSharedCriteriaResponse;
34+
import com.google.ads.googleads.v0.services.MutateSharedCriterionResult;
35+
import com.google.ads.googleads.v0.services.MutateSharedSetsResponse;
36+
import com.google.ads.googleads.v0.services.SharedCriterionOperation;
37+
import com.google.ads.googleads.v0.services.SharedCriterionServiceClient;
38+
import com.google.ads.googleads.v0.services.SharedSetOperation;
39+
import com.google.ads.googleads.v0.services.SharedSetServiceClient;
40+
import com.google.common.collect.ImmutableList;
41+
import com.google.protobuf.StringValue;
42+
import java.io.FileNotFoundException;
43+
import java.io.IOException;
44+
import java.util.ArrayList;
45+
import java.util.Arrays;
46+
import java.util.List;
47+
48+
/**
49+
* This example creates a shared list of negative broad match keywords. It then attaches them to a
50+
* campaign.
51+
*/
52+
public class CreateAndAttachSharedKeywordSet {
53+
54+
private static class CreateAndAttachSharedKeywordSetParams extends CodeSampleParams {
55+
56+
@Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
57+
private Long customerId;
58+
59+
@Parameter(names = ArgumentNames.CAMPAIGN_ID, required = true)
60+
private Long campaignId;
61+
}
62+
63+
public static void main(String[] args) throws IOException {
64+
CreateAndAttachSharedKeywordSetParams params = new CreateAndAttachSharedKeywordSetParams();
65+
if (!params.parseArguments(args)) {
66+
67+
// Either pass the required parameters for this example on the command line, or insert them
68+
// into the code here. See the parameter class definition above for descriptions.
69+
params.customerId = Long.parseLong("INSERT_CUSTOMER_ID_HERE");
70+
params.campaignId = Long.parseLong("INSERT_CAMPAIGN_ID_HERE");
71+
}
72+
73+
GoogleAdsClient googleAdsClient;
74+
try {
75+
googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
76+
} catch (FileNotFoundException fnfe) {
77+
System.err.printf(
78+
"Failed to load GoogleAdsClient configuration from file. Exception: %s%n", fnfe);
79+
return;
80+
} catch (IOException ioe) {
81+
System.err.printf("Failed to create GoogleAdsClient. Exception: %s%n", ioe);
82+
return;
83+
}
84+
85+
try {
86+
new CreateAndAttachSharedKeywordSet()
87+
.runExample(googleAdsClient, params.customerId, params.campaignId);
88+
} catch (GoogleAdsException gae) {
89+
// GoogleAdsException is the base class for most exceptions thrown by an API request.
90+
// Instances of this exception have a message and a GoogleAdsFailure that contains a
91+
// collection of GoogleAdsErrors that indicate the underlying causes of the
92+
// GoogleAdsException.
93+
System.err.printf(
94+
"Request ID %s failed due to GoogleAdsException. Underlying errors:%n",
95+
gae.getRequestId());
96+
int i = 0;
97+
for (GoogleAdsError googleAdsError : gae.getGoogleAdsFailure().getErrorsList()) {
98+
System.err.printf(" Error %d: %s%n", i++, googleAdsError);
99+
}
100+
}
101+
}
102+
103+
/**
104+
* Runs the example.
105+
*
106+
* @param googleAdsClient the Google Ads API client.
107+
* @param customerId the client customer ID.
108+
* @param campaignId the campaign ID.
109+
* @throws GoogleAdsException if an API request failed with one or more service errors.
110+
*/
111+
private void runExample(GoogleAdsClient googleAdsClient, long customerId, long campaignId) {
112+
113+
// Keywords to create a shared set of.
114+
List<String> keywords = Arrays.asList("mars cruise", "mars hotels");
115+
116+
// Create shared negative keyword set.
117+
SharedSet sharedSet =
118+
SharedSet.newBuilder()
119+
.setName(StringValue.of("API Negative keyword list - " + System.currentTimeMillis()))
120+
.setType(SharedSetType.NEGATIVE_KEYWORDS)
121+
.build();
122+
123+
SharedSetOperation operation = SharedSetOperation.newBuilder().setCreate(sharedSet).build();
124+
125+
String sharedSetResourceName;
126+
try (SharedSetServiceClient sharedSetServiceClient =
127+
googleAdsClient.getSharedSetServiceClient()) {
128+
MutateSharedSetsResponse response =
129+
sharedSetServiceClient.mutateSharedSets(
130+
Long.toString(customerId), ImmutableList.of(operation));
131+
sharedSetResourceName = response.getResults(0).getResourceName();
132+
System.out.printf("Created shared set %s%n", sharedSetResourceName);
133+
}
134+
135+
List<SharedCriterionOperation> sharedCriterionOperations = new ArrayList<>();
136+
for (String keyword : keywords) {
137+
SharedCriterion sharedCriterion =
138+
SharedCriterion.newBuilder()
139+
.setKeyword(
140+
KeywordInfo.newBuilder()
141+
.setText(StringValue.of(keyword))
142+
.setMatchType(KeywordMatchType.BROAD)
143+
.build())
144+
.setSharedSet(StringValue.of(sharedSetResourceName))
145+
.build();
146+
147+
SharedCriterionOperation sharedCriterionOperation =
148+
SharedCriterionOperation.newBuilder().setCreate(sharedCriterion).build();
149+
sharedCriterionOperations.add(sharedCriterionOperation);
150+
}
151+
152+
try (SharedCriterionServiceClient sharedCriterionServiceClient =
153+
googleAdsClient.getSharedCriterionServiceClient()) {
154+
MutateSharedCriteriaResponse response =
155+
sharedCriterionServiceClient.mutateSharedCriteria(
156+
Long.toString(customerId), sharedCriterionOperations);
157+
System.out.printf("Added %d shared criteria:%n", response.getResultsCount());
158+
for (MutateSharedCriterionResult result : response.getResultsList()) {
159+
System.out.printf("\t%s%n", result.getResourceName());
160+
}
161+
}
162+
163+
String campaignResourceName =
164+
CampaignName.format(Long.toString(customerId), Long.toString(campaignId));
165+
CampaignSharedSet campaignSharedSet =
166+
CampaignSharedSet.newBuilder()
167+
.setCampaign(StringValue.of(campaignResourceName))
168+
.setSharedSet(StringValue.of(sharedSetResourceName))
169+
.build();
170+
171+
CampaignSharedSetOperation campaignSharedSetOperation =
172+
CampaignSharedSetOperation.newBuilder().setCreate(campaignSharedSet).build();
173+
174+
try (CampaignSharedSetServiceClient campaignSharedSetServiceClient =
175+
googleAdsClient.getCampaignSharedSetServiceClient()) {
176+
MutateCampaignSharedSetsResponse response =
177+
campaignSharedSetServiceClient.mutateCampaignSharedSets(
178+
Long.toString(customerId), ImmutableList.of(campaignSharedSetOperation));
179+
String campaignSharedSetResourceName = response.getResults(0).getResourceName();
180+
System.out.printf("Created campaign shared set %s%n", campaignSharedSetResourceName);
181+
}
182+
}
183+
}

0 commit comments

Comments
 (0)