Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82d2093

Browse files
authored
Merge pull request googleworkspace#1 from gsuitedevs/master
Syncing to master.
2 parents b788a9e + 0a4affc commit 82d2093

File tree

52 files changed

+2448
-379
lines changed

Some content is hidden

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

52 files changed

+2448
-379
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(Please fill out these details before submitting an issue)
2+
3+
### Sample Name
4+
(i.e. Gmail Quickstart)
5+
6+
### Expected Behavior
7+
8+
### Actual Behavior
9+
10+
### Specifications
11+
- Java version (`java -version`)
12+
- OS (Mac/Linux/Windows)

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ gradlew.bat
3030
*.properties
3131

3232
client_secret.json
33+
credentials.json
34+
tokens/
3335

3436
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
3537
hs_err_pid*
3638

3739
.DS_Store
40+
.settings/
41+
.classpath
42+
.project
43+
properties

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
language: java
22
jdk:
33
- oraclejdk8
4-
- oraclejdk9
4+
# - oraclejdk9
55
# Use a Build Matrix for subdirs (https://lord.io/blog/2014/travis-multiple-subdirs/)
66
env:
7+
- DIR=adminSDK/alertcenter/quickstart
78
- DIR=adminSDK/directory/quickstart
8-
- DIR=adminSDK/groupsMigration/quickstart
9-
- DIR=adminSDK/groupsSettings/quickstart
10-
- DIR=adminSDK/licensing/quickstart
119
- DIR=adminSDK/reports/quickstart
1210
- DIR=adminSDK/reseller/quickstart
1311
- DIR=appsScript/quickstart
@@ -17,4 +15,4 @@ env:
1715
- DIR=sheets/quickstart
1816
- DIR=slides/quickstart
1917
- DIR=tasks/quickstart
20-
script: cd $DIR && gradle -q run
18+
script: cd $DIR && gradle build # gradle -q run

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ A collection of samples that demonstrate how to call G Suite APIs in Java.
66

77
### Admin SDK
88

9+
- [Alert Center Quickstart](https://developers.google.com/admin-sdk/alertcenter/quickstart/java)
910
- [Directory Quickstart](https://developers.google.com/admin-sdk/directory/v1/quickstart/java)
10-
- [Group Migration Quickstart](https://developers.google.com/admin-sdk/groups-migration/v1/quickstart/java)
11-
- [Group Settings Quickstart](https://developers.google.com/admin-sdk/groups-settings/quickstart/java)
12-
- [Licensing Quickstart](https://developers.google.com/admin-sdk/licensing/v1/quickstart/java)
1311
- [Reports Quickstart](https://developers.google.com/admin-sdk/reports/v1/quickstart/java)
1412
- [Reseller Quickstart](https://developers.google.com/admin-sdk/reseller/v1/quickstart/java)
1513

@@ -21,6 +19,7 @@ A collection of samples that demonstrate how to call G Suite APIs in Java.
2119

2220
- [Quickstart](https://developers.google.com/calendar/quickstart/java)
2321
- [Sync Tokens and Etags](calendar/sync)
22+
- [Command line sample](https://github.com/google/google-api-java-client-samples/tree/master/calendar-cmdline-sample)
2423

2524
### Classroom
2625

@@ -29,11 +28,16 @@ A collection of samples that demonstrate how to call G Suite APIs in Java.
2928
### Drive V3
3029

3130
- [Quickstart](https://developers.google.com/drive/v3/web/quickstart/java)
31+
- [Command line sample](https://github.com/google/google-api-java-client-samples/tree/master/drive-cmdline-sample)
3232

3333
### Gmail
3434

3535
- [Quickstart](https://developers.google.com/gmail/api/quickstart/java)
3636

37+
### People
38+
39+
- [Quickstart](https://developers.google.com/people/quickstart/java)
40+
3741
### Sheets
3842

3943
- [Quickstart](https://developers.google.com/sheets/api/quickstart/java)
@@ -45,3 +49,7 @@ A collection of samples that demonstrate how to call G Suite APIs in Java.
4549
### Tasks
4650

4751
- [Quickstart](https://developers.google.com/google-apps/tasks/quickstart/java)
52+
53+
### Vault
54+
55+
- [Quickstart](https://developers.google.com/vault/quickstart/java)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apply plugin: 'java'
2+
apply plugin: 'application'
3+
apply plugin: 'idea'
4+
5+
mainClassName = 'AdminSDKAlertCenterQuickstart'
6+
sourceCompatibility = 1.8
7+
targetCompatibility = 1.8
8+
version = '1.0'
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
compile 'com.google.api-client:google-api-client:1.20.0'
16+
compile 'com.google.auth:google-auth-library-oauth2-http:0.11.0'
17+
compile 'com.google.apis:google-api-services-alertcenter:v1beta1-rev7-1.25.0'
18+
}
File renamed without changes.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
// http://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+
// [START admin_sdk_alertcenter_quickstart]
16+
17+
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
18+
import com.google.api.client.http.javanet.NetHttpTransport;
19+
import com.google.api.client.json.JsonFactory;
20+
import com.google.api.client.json.jackson2.JacksonFactory;
21+
import com.google.api.services.alertcenter.v1beta1.AlertCenter;
22+
import com.google.api.services.alertcenter.v1beta1.model.Alert;
23+
import com.google.api.services.alertcenter.v1beta1.model.AlertFeedback;
24+
import com.google.api.services.alertcenter.v1beta1.model.ListAlertsResponse;
25+
import com.google.auth.Credentials;
26+
import com.google.auth.http.HttpCredentialsAdapter;
27+
import com.google.auth.oauth2.GoogleCredentials;
28+
import com.google.auth.oauth2.ServiceAccountCredentials;
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
import java.security.GeneralSecurityException;
32+
import java.util.Collections;
33+
import java.util.List;
34+
35+
public class AdminSDKAlertCenterQuickstart {
36+
37+
private static final String APPLICATION_NAME = "Google Admin SDK Alert Center API Java Quickstart";
38+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
39+
/**
40+
* Global instance of the scopes required by this quickstart. If modifying these scopes, delete
41+
* your previously saved tokens/ folder.
42+
*/
43+
private static final List<String> SCOPES = Collections
44+
.singletonList("https://www.googleapis.com/auth/apps.alerts");
45+
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
46+
private static final String DELEGATED_ADMIN_EMAIL = "[email protected]";
47+
48+
/**
49+
* Creates an authorized Credentials object.
50+
*
51+
* @param delegatedAdminEmail A delegated admin email to associate with the created credentials.
52+
* @return An authorized Credentials object.
53+
* @throws IOException If the credentials.json file cannot be found.
54+
*/
55+
private static Credentials getCredentials(String delegatedAdminEmail) throws IOException {
56+
// [START admin_sdk_alertcenter_get_credentials]
57+
InputStream in = AdminSDKAlertCenterQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
58+
if (in == null) {
59+
throw new IOException("Credential file was not found");
60+
}
61+
GoogleCredentials credentials = ServiceAccountCredentials
62+
.fromStream(in)
63+
.createDelegated(delegatedAdminEmail)
64+
.createScoped(SCOPES);
65+
// [END admin_sdk_alertcenter_get_credentials]
66+
return credentials;
67+
}
68+
69+
public static void main(String... args) throws IOException, GeneralSecurityException {
70+
// [START admin_sdk_alertcenter_create_client]
71+
72+
NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
73+
AlertCenter service = new AlertCenter.Builder(transport, JSON_FACTORY,
74+
new HttpCredentialsAdapter(getCredentials(DELEGATED_ADMIN_EMAIL)))
75+
.setApplicationName(APPLICATION_NAME)
76+
.build();
77+
// [END admin_sdk_alertcenter_create_client]
78+
79+
// [START admin_sdk_alertcenter_list_alerts]
80+
String pageToken = null;
81+
do {
82+
ListAlertsResponse listResponse = service.alerts().list().setPageToken(pageToken)
83+
.setPageSize(20).execute();
84+
if (listResponse.getAlerts() != null) {
85+
for (Alert alert : listResponse.getAlerts()) {
86+
System.out.println(alert);
87+
}
88+
}
89+
pageToken = listResponse.getNextPageToken();
90+
} while (pageToken != null);
91+
// [END admin_sdk_alertcenter_list_alerts]
92+
93+
ListAlertsResponse listResponse = service.alerts().list().setPageSize(20).execute();
94+
if (listResponse == null || listResponse.isEmpty()) {
95+
System.out.println("No alerts");
96+
} else {
97+
String alertId = listResponse.getAlerts().get(0).getAlertId();
98+
// Uncomment the line below to set alert feedback.
99+
// setAlertFeedback(service, alertId);
100+
}
101+
}
102+
103+
private static void setAlertFeedback(AlertCenter service, String alertId) throws IOException {
104+
// [START admin_sdk_alertcenter_provide_feedback]
105+
AlertFeedback newFeedback = new AlertFeedback();
106+
newFeedback.setType("VERY_USEFUL");
107+
AlertFeedback feedback = service.alerts().feedback().create(alertId, newFeedback).execute();
108+
System.out.println(feedback);
109+
// [END admin_sdk_alertcenter_provide_feedback]
110+
}
111+
}
112+
// [END admin_sdk_alertcenter_quickstart]

adminSDK/directory/quickstart/src/main/java/AdminSDKDirectoryQuickstart.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,34 @@
3838
public class AdminSDKDirectoryQuickstart {
3939
private static final String APPLICATION_NAME = "Google Admin SDK Directory API Java Quickstart";
4040
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
41-
private static final String CREDENTIALS_FOLDER = "credentials"; // Directory to store user credentials.
41+
private static final String TOKENS_DIRECTORY_PATH = "tokens";
4242

4343
/**
4444
* Global instance of the scopes required by this quickstart.
45-
* If modifying these scopes, delete your previously saved credentials folder at /secret.
45+
* If modifying these scopes, delete your previously saved tokens/ folder.
4646
*/
4747
private static final List<String> SCOPES = Collections.singletonList(DirectoryScopes.ADMIN_DIRECTORY_USER_READONLY);
48-
private static final String CLIENT_SECRET_DIR = "client_secret.json";
48+
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
4949

5050
/**
5151
* Creates an authorized Credential object.
5252
* @param HTTP_TRANSPORT The network HTTP Transport.
5353
* @return An authorized Credential object.
54-
* @throws IOException If there is no client_secret.
54+
* @throws IOException If the credentials.json file cannot be found.
5555
*/
5656
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
5757
// Load client secrets.
58-
InputStream in = AdminSDKDirectoryQuickstart.class.getResourceAsStream(CLIENT_SECRET_DIR);
58+
InputStream in = AdminSDKDirectoryQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
5959
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
6060

6161
// Build flow and trigger user authorization request.
6262
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
6363
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
64-
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(CREDENTIALS_FOLDER)))
64+
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
6565
.setAccessType("offline")
6666
.build();
67-
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
67+
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
68+
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
6869
}
6970

7071
public static void main(String... args) throws IOException, GeneralSecurityException {

adminSDK/groupsMigration/quickstart/build.gradle

Lines changed: 0 additions & 22 deletions
This file was deleted.

adminSDK/groupsMigration/quickstart/src/main/java/AdminSDKGroupsMigrationQuickstart.java

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)