Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit 537a7c8

Browse files
committed
api samples: Update samples to 1.16.0-rc
https://codereview.appspot.com/11587043
1 parent b383ad3 commit 537a7c8

File tree

126 files changed

+1139
-912
lines changed

Some content is hidden

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

126 files changed

+1139
-912
lines changed

adexchangebuyer-cmdline-sample/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<dependency>
115115
<groupId>com.google.apis</groupId>
116116
<artifactId>google-api-services-adexchangebuyer</artifactId>
117-
<version>v1.2-rev6-1.15.0-rc</version>
117+
<version>v1.2-rev11-1.16.0-rc</version>
118118
</dependency>
119119
<dependency>
120120
<groupId>com.google.http-client</groupId>
@@ -128,8 +128,8 @@
128128
</dependency>
129129
</dependencies>
130130
<properties>
131-
<project.http.version>1.15.0-rc</project.http.version>
132-
<project.oauth.version>1.15.0-rc</project.oauth.version>
131+
<project.http.version>1.16.0-rc</project.http.version>
132+
<project.oauth.version>1.16.0-rc</project.oauth.version>
133133
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
134134
</properties>
135135
</project>

adexchangebuyer-cmdline-sample/src/main/java/com/google/api/services/samples/adexchangebuyer/cmdline/AdExchangeBuyerSample.java

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* Copyright (c) 2012 Google Inc.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
6-
*
6+
*
77
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
8+
*
99
* Unless required by applicable law or agreed to in writing, software distributed under the License
1010
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1111
* or implied. See the License for the specific language governing permissions and limitations under
@@ -16,18 +16,18 @@
1616

1717
import com.google.api.client.auth.oauth2.Credential;
1818
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
19-
import com.google.api.client.extensions.java6.auth.oauth2.FileCredentialStore;
2019
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
2120
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
2221
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
2322
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
2423
import com.google.api.client.http.HttpTransport;
2524
import com.google.api.client.json.JsonFactory;
2625
import com.google.api.client.json.jackson2.JacksonFactory;
26+
import com.google.api.client.util.store.DataStoreFactory;
27+
import com.google.api.client.util.store.FileDataStoreFactory;
2728
import com.google.api.services.adexchangebuyer.Adexchangebuyer;
2829
import com.google.api.services.adexchangebuyer.AdexchangebuyerScopes;
2930

30-
import java.io.File;
3131
import java.io.IOException;
3232
import java.io.InputStreamReader;
3333
import java.util.ArrayList;
@@ -51,7 +51,17 @@ public class AdExchangeBuyerSample {
5151
* blank, the application will log a warning. Suggested format is "MyCompany-ProductName/1.0".
5252
*/
5353
private static final String APPLICATION_NAME = "";
54-
54+
55+
/** Directory to store user credentials. */
56+
private static final java.io.File DATA_STORE_DIR =
57+
new java.io.File(System.getProperty("user.home"), ".store/ad_exchange_buyer_sample");
58+
59+
/**
60+
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
61+
* globally shared instance across your application.
62+
*/
63+
private static FileDataStoreFactory DATA_STORE_FACTORY;
64+
5565
/** Global instance of the HTTP transport. */
5666
private static HttpTransport HTTP_TRANSPORT;
5767

@@ -73,22 +83,18 @@ JSON_FACTORY, new InputStreamReader(
7383
+ "adexchangebuyer-cmdline-sample/src/main/resources/client_secrets.json");
7484
System.exit(1);
7585
}
76-
// set up file credential store
77-
FileCredentialStore credentialStore = new FileCredentialStore(
78-
new File(System.getProperty("user.home"), ".credentials/adexchangebuyer.json"),
79-
JSON_FACTORY);
8086
// set up authorization code flow
8187
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
8288
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
83-
Collections.singleton(AdexchangebuyerScopes.ADEXCHANGE_BUYER)).setCredentialStore(
84-
credentialStore).build();
89+
Collections.singleton(AdexchangebuyerScopes.ADEXCHANGE_BUYER)).setDataStoreFactory(
90+
DATA_STORE_FACTORY).build();
8591
// authorize
8692
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
8793
}
8894

8995
/**
9096
* Performs all necessary setup steps for running requests against the API.
91-
*
97+
*
9298
* @return An initialized AdSense service object.
9399
* @throws Exception
94100
*/
@@ -98,8 +104,7 @@ private static Adexchangebuyer initClient() throws Exception {
98104

99105
// Set up API client.
100106
Adexchangebuyer client = new Adexchangebuyer.Builder(
101-
HTTP_TRANSPORT, JSON_FACTORY, credential)
102-
.setApplicationName(APPLICATION_NAME).build();
107+
HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
103108

104109
return client;
105110
}
@@ -118,12 +123,13 @@ private static void initSamples() {
118123

119124
/**
120125
* Runs all the Ad Exchange Buyer API samples.
121-
*
126+
*
122127
* @param args command-line arguments.
123128
* @throws Exception
124129
*/
125130
public static void main(String[] args) throws Exception {
126131
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
132+
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
127133
initSamples();
128134
Adexchangebuyer client = initClient();
129135
BaseSample sample = null;
@@ -141,7 +147,7 @@ public static void main(String[] args) throws Exception {
141147

142148
/**
143149
* Prints the list of available code samples and prompts the user to select one.
144-
*
150+
*
145151
* @return The selected sample or null if the user selected to exit
146152
* @throws IOException
147153
*/

adsense-cmdline-sample/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<dependency>
115115
<groupId>com.google.apis</groupId>
116116
<artifactId>google-api-services-adsense</artifactId>
117-
<version>v1.3-rev2-1.15.0-rc</version>
117+
<version>v1.3-rev19-1.16.0-rc</version>
118118
</dependency>
119119
<dependency>
120120
<groupId>com.google.http-client</groupId>
@@ -128,8 +128,8 @@
128128
</dependency>
129129
</dependencies>
130130
<properties>
131-
<project.http.version>1.15.0-rc</project.http.version>
132-
<project.oauth.version>1.15.0-rc</project.oauth.version>
131+
<project.http.version>1.16.0-rc</project.http.version>
132+
<project.oauth.version>1.16.0-rc</project.oauth.version>
133133
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
134134
</properties>
135135
</project>

adsense-cmdline-sample/src/main/java/com/google/api/services/samples/adsense/cmdline/AdSenseSample.java

+71-64
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import com.google.api.client.auth.oauth2.Credential;
1818
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
19-
import com.google.api.client.extensions.java6.auth.oauth2.FileCredentialStore;
2019
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
2120
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
2221
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
@@ -25,6 +24,8 @@
2524
import com.google.api.client.http.javanet.NetHttpTransport;
2625
import com.google.api.client.json.JsonFactory;
2726
import com.google.api.client.json.jackson2.JacksonFactory;
27+
import com.google.api.client.util.store.DataStoreFactory;
28+
import com.google.api.client.util.store.FileDataStoreFactory;
2829
import com.google.api.services.adsense.AdSense;
2930
import com.google.api.services.adsense.AdSenseScopes;
3031
import com.google.api.services.adsense.model.Accounts;
@@ -33,14 +34,13 @@
3334
import com.google.api.services.adsense.model.CustomChannels;
3435
import com.google.api.services.adsense.model.SavedReports;
3536

36-
import java.io.File;
3737
import java.io.IOException;
3838
import java.io.InputStreamReader;
3939
import java.util.Collections;
4040

4141
/**
42-
* A sample application that runs multiple requests against the AdSense Management API.
43-
* These include:
42+
* A sample application that runs multiple requests against the AdSense Management API. These
43+
* include:
4444
* <ul>
4545
* <li>Listing all AdSense accounts for a user</li>
4646
* <li>Listing the sub-account tree for an account</li>
@@ -69,6 +69,16 @@ public class AdSenseSample {
6969
*/
7070
private static final String APPLICATION_NAME = "";
7171

72+
/** Directory to store user credentials. */
73+
private static final java.io.File DATA_STORE_DIR =
74+
new java.io.File(System.getProperty("user.home"), ".store/adsense_management_sample");
75+
76+
/**
77+
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
78+
* globally shared instance across your application.
79+
*/
80+
private static FileDataStoreFactory DATA_STORE_FACTORY;
81+
7282
/** Global instance of the JSON factory. */
7383
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
7484

@@ -91,21 +101,18 @@ private static Credential authorize() throws Exception {
91101
+ "adsense-cmdline-sample/src/main/resources/client_secrets.json");
92102
System.exit(1);
93103
}
94-
// set up file credential store
95-
FileCredentialStore credentialStore = new FileCredentialStore(
96-
new File(System.getProperty("user.home"), ".credentials/adsense.json"),
97-
JSON_FACTORY);
98104
// set up authorization code flow
99105
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
100106
httpTransport, JSON_FACTORY, clientSecrets,
101-
Collections.singleton(AdSenseScopes.ADSENSE_READONLY)).setCredentialStore(
102-
credentialStore).build();
107+
Collections.singleton(AdSenseScopes.ADSENSE_READONLY)).setDataStoreFactory(
108+
DATA_STORE_FACTORY).build();
103109
// authorize
104110
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
105111
}
106112

107113
/**
108114
* Performs all necessary setup steps for running requests against the API.
115+
*
109116
* @return An initialized AdSense service object.
110117
* @throws Exception
111118
*/
@@ -115,78 +122,78 @@ private static AdSense initializeAdsense() throws Exception {
115122

116123
// Set up AdSense Management API client.
117124
AdSense adsense = new AdSense.Builder(
118-
new NetHttpTransport(), JSON_FACTORY, credential)
119-
.setApplicationName(APPLICATION_NAME).build();
125+
new NetHttpTransport(), JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME)
126+
.build();
120127

121128
return adsense;
122129
}
123130

124131
/**
125132
* Runs all the AdSense Management API samples.
133+
*
126134
* @param args command-line arguments.
127135
*/
128136
public static void main(String[] args) {
129137
try {
130-
try {
131-
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
132-
AdSense adsense = initializeAdsense();
133-
134-
Accounts accounts = GetAllAccounts.run(adsense, MAX_LIST_PAGE_SIZE);
135-
if ((accounts.getItems() != null) && !accounts.getItems().isEmpty()) {
136-
// Get an example account ID, so we can run the following sample.
137-
String exampleAccountId = accounts.getItems().get(0).getId();
138-
GetAccountTree.run(adsense, exampleAccountId);
139-
GetAllAdClientsForAccount.run(adsense, exampleAccountId, MAX_LIST_PAGE_SIZE);
140-
}
138+
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
139+
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
140+
AdSense adsense = initializeAdsense();
141+
142+
Accounts accounts = GetAllAccounts.run(adsense, MAX_LIST_PAGE_SIZE);
143+
if ((accounts.getItems() != null) && !accounts.getItems().isEmpty()) {
144+
// Get an example account ID, so we can run the following sample.
145+
String exampleAccountId = accounts.getItems().get(0).getId();
146+
GetAccountTree.run(adsense, exampleAccountId);
147+
GetAllAdClientsForAccount.run(adsense, exampleAccountId, MAX_LIST_PAGE_SIZE);
148+
}
141149

142-
AdClients adClients = GetAllAdClients.run(adsense, MAX_LIST_PAGE_SIZE);
143-
if ((adClients.getItems() != null) && !adClients.getItems().isEmpty()) {
144-
// Get an ad client ID, so we can run the rest of the samples.
145-
String exampleAdClientId = adClients.getItems().get(0).getId();
146-
147-
AdUnits units = GetAllAdUnits.run(adsense, exampleAdClientId, MAX_LIST_PAGE_SIZE);
148-
if ((units.getItems() != null) && !units.getItems().isEmpty()) {
149-
// Get an example ad unit ID, so we can run the following sample.
150-
String exampleAdUnitId = units.getItems().get(0).getId();
151-
GetAllCustomChannelsForAdUnit.run(adsense, exampleAdClientId, exampleAdUnitId,
152-
MAX_LIST_PAGE_SIZE);
153-
}
154-
155-
CustomChannels channels = GetAllCustomChannels.run(adsense, exampleAdClientId,
156-
MAX_LIST_PAGE_SIZE);
157-
if ((channels.getItems() != null) && !channels.getItems().isEmpty()) {
158-
// Get an example custom channel ID, so we can run the following sample.
159-
String exampleCustomChannelId = channels.getItems().get(0).getId();
160-
GetAllAdUnitsForCustomChannel.run(adsense, exampleAdClientId, exampleCustomChannelId,
161-
MAX_LIST_PAGE_SIZE);
162-
}
163-
164-
GetAllUrlChannels.run(adsense, exampleAdClientId, MAX_LIST_PAGE_SIZE);
165-
GenerateReport.run(adsense, exampleAdClientId);
166-
GenerateReportWithPaging.run(adsense, exampleAdClientId, MAX_REPORT_PAGE_SIZE);
167-
} else {
168-
System.out.println("No ad clients found, unable to run remaining methods.");
150+
AdClients adClients = GetAllAdClients.run(adsense, MAX_LIST_PAGE_SIZE);
151+
if ((adClients.getItems() != null) && !adClients.getItems().isEmpty()) {
152+
// Get an ad client ID, so we can run the rest of the samples.
153+
String exampleAdClientId = adClients.getItems().get(0).getId();
154+
155+
AdUnits units = GetAllAdUnits.run(adsense, exampleAdClientId, MAX_LIST_PAGE_SIZE);
156+
if ((units.getItems() != null) && !units.getItems().isEmpty()) {
157+
// Get an example ad unit ID, so we can run the following sample.
158+
String exampleAdUnitId = units.getItems().get(0).getId();
159+
GetAllCustomChannelsForAdUnit.run(
160+
adsense, exampleAdClientId, exampleAdUnitId, MAX_LIST_PAGE_SIZE);
169161
}
170162

171-
SavedReports savedReports = GetAllSavedReports.run(adsense, MAX_REPORT_PAGE_SIZE);
172-
if ((savedReports.getItems() != null) && !savedReports.getItems().isEmpty()){
173-
// Get a saved report ID, so we can generate its report.
174-
String exampleSavedReportId = savedReports.getItems().get(0).getId();
175-
GenerateSavedReport.run(adsense, exampleSavedReportId);
176-
} else {
177-
System.out.println("No saved report found.");
163+
CustomChannels channels =
164+
GetAllCustomChannels.run(adsense, exampleAdClientId, MAX_LIST_PAGE_SIZE);
165+
if ((channels.getItems() != null) && !channels.getItems().isEmpty()) {
166+
// Get an example custom channel ID, so we can run the following sample.
167+
String exampleCustomChannelId = channels.getItems().get(0).getId();
168+
GetAllAdUnitsForCustomChannel.run(
169+
adsense, exampleAdClientId, exampleCustomChannelId, MAX_LIST_PAGE_SIZE);
178170
}
179171

180-
GetAllSavedAdStyles.run(adsense, MAX_LIST_PAGE_SIZE);
172+
GetAllUrlChannels.run(adsense, exampleAdClientId, MAX_LIST_PAGE_SIZE);
173+
GenerateReport.run(adsense, exampleAdClientId);
174+
GenerateReportWithPaging.run(adsense, exampleAdClientId, MAX_REPORT_PAGE_SIZE);
175+
} else {
176+
System.out.println("No ad clients found, unable to run remaining methods.");
177+
}
181178

182-
GetAllDimensions.run(adsense);
183-
GetAllMetrics.run(adsense);
179+
SavedReports savedReports = GetAllSavedReports.run(adsense, MAX_REPORT_PAGE_SIZE);
180+
if ((savedReports.getItems() != null) && !savedReports.getItems().isEmpty()) {
181+
// Get a saved report ID, so we can generate its report.
182+
String exampleSavedReportId = savedReports.getItems().get(0).getId();
183+
GenerateSavedReport.run(adsense, exampleSavedReportId);
184+
} else {
185+
System.out.println("No saved report found.");
186+
}
184187

185-
GetAllAlerts.run(adsense);
188+
GetAllSavedAdStyles.run(adsense, MAX_LIST_PAGE_SIZE);
186189

187-
} catch (IOException e) {
188-
System.err.println(e.getMessage());
189-
}
190+
GetAllDimensions.run(adsense);
191+
GetAllMetrics.run(adsense);
192+
193+
GetAllAlerts.run(adsense);
194+
195+
} catch (IOException e) {
196+
System.err.println(e.getMessage());
190197
} catch (Throwable t) {
191198
t.printStackTrace();
192199
}

adsensehost-cmdline-sample/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<dependency>
115115
<groupId>com.google.apis</groupId>
116116
<artifactId>google-api-services-adsensehost</artifactId>
117-
<version>v4.1-rev36-1.15.0-rc</version>
117+
<version>v4.1-rev60-1.16.0-rc</version>
118118
</dependency>
119119
<dependency>
120120
<groupId>com.google.http-client</groupId>
@@ -128,8 +128,8 @@
128128
</dependency>
129129
</dependencies>
130130
<properties>
131-
<project.http.version>1.15.0-rc</project.http.version>
132-
<project.oauth.version>1.15.0-rc</project.oauth.version>
131+
<project.http.version>1.16.0-rc</project.http.version>
132+
<project.oauth.version>1.16.0-rc</project.oauth.version>
133133
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
134134
</properties>
135135
</project>

0 commit comments

Comments
 (0)