Skip to content

Commit be18f8b

Browse files
authored
Changes for release v0_4.
* Changes for release v0_4. * Prepare change log for 0.4.0.
1 parent cb2ff28 commit be18f8b

334 files changed

Lines changed: 74136 additions & 1458 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
0.4.0 - 2018-09-25
2+
------------------
3+
Added support and examples for Google Ads API v0_4.
4+
5+
- Added examples showing how to add and get account budget proposals.
6+
- Added examples showing how to get and remove billing setups.
7+
- Added an example showing how to retrieve all disapproved ads in a campaign.
8+
- Added an example showing how to add a conversion action.
9+
- Added an example showing how to create a standard shopping campaign, a
10+
shopping product ad group, and a shopping product ad.
11+
- Added an example showing how to add a shopping listing group tree to a
12+
shopping ad group.
13+
114
0.3.2 - 2018-08-29
215
------------------
316
Added support and examples for Google Ads API v0_3.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
package com.google.ads.googleads.examples.billing;
15+
16+
import com.beust.jcommander.Parameter;
17+
import com.google.ads.googleads.examples.utils.ArgumentNames;
18+
import com.google.ads.googleads.examples.utils.CodeSampleParams;
19+
import com.google.ads.googleads.lib.GoogleAdsClient;
20+
import com.google.ads.googleads.lib.GoogleAdsException;
21+
import com.google.ads.googleads.v0.enums.AccountBudgetProposalTypeEnum.AccountBudgetProposalType;
22+
import com.google.ads.googleads.v0.enums.TimeTypeEnum.TimeType;
23+
import com.google.ads.googleads.v0.errors.GoogleAdsError;
24+
import com.google.ads.googleads.v0.resources.AccountBudgetProposal;
25+
import com.google.ads.googleads.v0.resources.BillingSetupName;
26+
import com.google.ads.googleads.v0.services.AccountBudgetProposalOperation;
27+
import com.google.ads.googleads.v0.services.AccountBudgetProposalServiceClient;
28+
import com.google.ads.googleads.v0.services.MutateAccountBudgetProposalResponse;
29+
import com.google.protobuf.Int64Value;
30+
import com.google.protobuf.StringValue;
31+
import java.io.FileNotFoundException;
32+
import java.io.IOException;
33+
34+
/**
35+
* This example creates an account budget proposal using the 'CREATE' operation. To get account
36+
* budget proposals, run GetAccountBudgetProposals.java.
37+
*/
38+
public class AddAccountBudgetProposal {
39+
40+
private static class AddAccountBudgetProposalParams extends CodeSampleParams {
41+
42+
@Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
43+
private Long customerId;
44+
45+
@Parameter(names = ArgumentNames.BILLING_SETUP_ID, required = true)
46+
private Long billingSetupId;
47+
}
48+
49+
public static void main(String[] args) {
50+
AddAccountBudgetProposalParams params = new AddAccountBudgetProposalParams();
51+
if (!params.parseArguments(args)) {
52+
53+
// Either pass the required parameters for this example on the command line, or insert them
54+
// into the code here. See the parameter class definition above for descriptions.
55+
params.customerId = Long.parseLong("INSERT_CUSTOMER_ID_HERE");
56+
params.billingSetupId = Long.parseLong("INSERT_BILLING_SETUP_ID_HERE");
57+
}
58+
59+
GoogleAdsClient googleAdsClient;
60+
try {
61+
googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
62+
} catch (FileNotFoundException fnfe) {
63+
System.err.printf(
64+
"Failed to load GoogleAdsClient configuration from file. Exception: %s%n", fnfe);
65+
return;
66+
} catch (IOException ioe) {
67+
System.err.printf("Failed to create GoogleAdsClient. Exception: %s%n", ioe);
68+
return;
69+
}
70+
71+
try {
72+
new AddAccountBudgetProposal()
73+
.runExample(googleAdsClient, params.customerId, params.billingSetupId);
74+
} catch (GoogleAdsException gae) {
75+
// GoogleAdsException is the base class for most exceptions thrown by an API request.
76+
// Instances of this exception have a message and a GoogleAdsFailure that contains a
77+
// collection of GoogleAdsErrors that indicate the underlying causes of the
78+
// GoogleAdsException.
79+
System.err.printf(
80+
"Request ID %s failed due to GoogleAdsException. Underlying errors:%n",
81+
gae.getRequestId());
82+
int i = 0;
83+
for (GoogleAdsError googleAdsError : gae.getGoogleAdsFailure().getErrorsList()) {
84+
System.err.printf(" Error %d: %s%n", i++, googleAdsError);
85+
}
86+
}
87+
}
88+
89+
private void runExample(GoogleAdsClient googleAdsClient, long customerId, long billingSetupId) {
90+
// Create an AccountBudgetProposal, this will be reviewed offline by Google Ads, and if approved
91+
// will become an AccountBudget.
92+
AccountBudgetProposal proposal = AccountBudgetProposal.newBuilder()
93+
.setBillingSetup(StringValue.of(BillingSetupName
94+
.format(String.valueOf(customerId), String.valueOf(billingSetupId))))
95+
.setProposalType(AccountBudgetProposalType.CREATE)
96+
.setProposedName(StringValue.of("Account Budget (example)"))
97+
98+
// Specify the account budget starts immediately
99+
.setProposedStartTimeType(TimeType.NOW)
100+
// Alternatively you can specify a specific start time. Refer to the AccountBudgetProposal
101+
// resource documentation for allowed formats.
102+
//
103+
//.setProposedStartDateTime(StringValue.of("2020-01-02 03:04:05"))
104+
105+
// Specify that the budget runs forever.
106+
.setProposedEndTimeType(TimeType.FOREVER)
107+
// Alternatively you can specify a specific end time. Allowed formats are as above.
108+
//.setProposedEndDateTime(StringValue.of("2021-02-03 04:05:06"))
109+
110+
// Optional: set notes for the budget. These are free text and do not effect budget
111+
// delivery.
112+
//.setProposedNotes(StringValue.of("Received prepayment of $0.01"))
113+
114+
// Set the spending limit to 0.01, measured in the Google Ads account currency.
115+
.setProposedSpendingLimitMicros(Int64Value.of(10_000))
116+
117+
// Optional: set PO number for record keeping. This value is at the user's
118+
// discretion, and has no effect on Google Billing & Payments.
119+
//.setProposedPurchaseOrderNumber(StringValue.of("PO number 12345"))
120+
.build();
121+
122+
// Create an operation which will add the new AccountBudgetProposal.
123+
AccountBudgetProposalOperation operation = AccountBudgetProposalOperation.newBuilder()
124+
.setCreate(proposal).build();
125+
126+
try (AccountBudgetProposalServiceClient accountBudgetProposalServiceClient = googleAdsClient
127+
.getAccountBudgetProposalServiceClient()) {
128+
// Send the request to the Account Budget Proposal Service.
129+
MutateAccountBudgetProposalResponse response = accountBudgetProposalServiceClient
130+
.mutateAccountBudgetProposal(String.valueOf(customerId), operation);
131+
132+
System.out
133+
.printf("Account budget proposal created: %s.%n", response.getResult().getResourceName());
134+
}
135+
}
136+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
package com.google.ads.googleads.examples.billing;
15+
16+
import com.beust.jcommander.Parameter;
17+
import com.google.ads.googleads.examples.utils.ArgumentNames;
18+
import com.google.ads.googleads.examples.utils.CodeSampleParams;
19+
import com.google.ads.googleads.lib.GoogleAdsClient;
20+
import com.google.ads.googleads.lib.GoogleAdsException;
21+
import com.google.ads.googleads.v0.errors.GoogleAdsError;
22+
import com.google.ads.googleads.v0.resources.AccountBudgetProposal;
23+
import com.google.ads.googleads.v0.services.GoogleAdsRow;
24+
import com.google.ads.googleads.v0.services.GoogleAdsServiceClient;
25+
import com.google.ads.googleads.v0.services.GoogleAdsServiceClient.SearchPagedResponse;
26+
import com.google.ads.googleads.v0.services.SearchGoogleAdsRequest;
27+
import java.io.FileNotFoundException;
28+
import java.io.IOException;
29+
30+
/**
31+
* This example gets all account budget proposals. To add an account budget proposal, run
32+
* AddAccountBudgetProposal.java.
33+
*/
34+
public class GetAccountBudgetProposals {
35+
36+
private static final int PAGE_SIZE = 1_000;
37+
38+
private static class GetAccountBudgetProposalsParams extends CodeSampleParams {
39+
40+
@Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
41+
private Long customerId;
42+
}
43+
44+
public static void main(String[] args) {
45+
GetAccountBudgetProposalsParams params = new GetAccountBudgetProposalsParams();
46+
if (!params.parseArguments(args)) {
47+
48+
// Either pass the required parameters for this example on the command line, or insert them
49+
// into the code here. See the parameter class definition above for descriptions.
50+
params.customerId = Long.parseLong("INSERT_CUSTOMER_ID_HERE");
51+
}
52+
53+
GoogleAdsClient googleAdsClient;
54+
try {
55+
googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
56+
} catch (FileNotFoundException fnfe) {
57+
System.err.printf(
58+
"Failed to load GoogleAdsClient configuration from file. Exception: %s%n", fnfe);
59+
return;
60+
} catch (IOException ioe) {
61+
System.err.printf("Failed to create GoogleAdsClient. Exception: %s%n", ioe);
62+
return;
63+
}
64+
65+
try {
66+
new GetAccountBudgetProposals().runExample(googleAdsClient, params.customerId);
67+
} catch (GoogleAdsException gae) {
68+
// GoogleAdsException is the base class for most exceptions thrown by an API request.
69+
// Instances of this exception have a message and a GoogleAdsFailure that contains a
70+
// collection of GoogleAdsErrors that indicate the underlying causes of the
71+
// GoogleAdsException.
72+
System.err.printf(
73+
"Request ID %s failed due to GoogleAdsException. Underlying errors:%n",
74+
gae.getRequestId());
75+
int i = 0;
76+
for (GoogleAdsError googleAdsError : gae.getGoogleAdsFailure().getErrorsList()) {
77+
System.err.printf(" Error %d: %s%n", i++, googleAdsError);
78+
}
79+
}
80+
}
81+
82+
/**
83+
* Runs the example.
84+
* @param googleAdsClient the Google Ads API client.
85+
* @param customerId the customer ID for which to retrieve AccountBudgetProposals.
86+
*/
87+
private void runExample(GoogleAdsClient googleAdsClient, long customerId) {
88+
// Construct a GAQL query which will retrieve AccountBudgetProposals.
89+
String queryString =
90+
"SELECT account_budget_proposal.id, "
91+
+ " account_budget_proposal.account_budget, "
92+
+ " account_budget_proposal.billing_setup, "
93+
+ " account_budget_proposal.status, "
94+
+ " account_budget_proposal.proposed_name, "
95+
+ " account_budget_proposal.proposed_notes, "
96+
+ " account_budget_proposal.proposed_purchase_order_number, "
97+
+ " account_budget_proposal.proposal_type, "
98+
+ " account_budget_proposal.approval_date_time, "
99+
+ " account_budget_proposal.creation_date_time "
100+
+ "FROM account_budget_proposal";
101+
102+
// Creates a request that will retrieve all account budget proposals using pages of the
103+
// specified page size.
104+
SearchGoogleAdsRequest request =
105+
SearchGoogleAdsRequest.newBuilder()
106+
.setCustomerId(Long.toString(customerId))
107+
.setPageSize(PAGE_SIZE)
108+
.setQuery(queryString)
109+
.build();
110+
111+
try (GoogleAdsServiceClient googleAdsServiceClient =
112+
googleAdsClient.getGoogleAdsServiceClient()) {
113+
// Issues the search request.
114+
SearchPagedResponse searchPagedResponse = googleAdsServiceClient.search(request);
115+
116+
// Iterates over all rows in all pages and prints the requested field values for the account
117+
// budget in each row.
118+
for (GoogleAdsRow googleAdsRow : searchPagedResponse.iterateAll()) {
119+
AccountBudgetProposal proposal = googleAdsRow.getAccountBudgetProposal();
120+
System.out.printf(
121+
"Account budget proposal with "
122+
+ "ID '%s' "
123+
+ "status '%s' "
124+
+ "account_budget '%s' "
125+
+ "billing_setup '%s' "
126+
+ "proposed_name '%s' "
127+
+ "proposed_notes '%s' "
128+
+ "proposed_po_number '%s' "
129+
+ "proposal_type '%s' "
130+
+ "approval_date_time '%s' "
131+
+ "creation_date_time '%s'.%n",
132+
proposal.getId().getValue(),
133+
proposal.getStatus().name(),
134+
proposal.getAccountBudget().getValue(),
135+
proposal.getBillingSetup().getValue(),
136+
proposal.getProposedName().getValue(),
137+
proposal.getProposedNotes().getValue(),
138+
proposal.getProposedPurchaseOrderNumber().getValue(),
139+
proposal.getProposalType().name(),
140+
proposal.getApprovalDateTime().getValue(),
141+
proposal.getCreationDateTime().getValue());
142+
}
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)