Skip to content

Commit 69f801b

Browse files
feat: Add samples for Drive Labels Advanced Service (googleworkspace#354)
* feat: Add samples for Drive Labels Advanced Service * Update advanced/driveLabels.gs Co-authored-by: Steve Bazyl <[email protected]> * Update advanced/driveLabels.gs Co-authored-by: Steve Bazyl <[email protected]> * Remove hard coded value Co-authored-by: Steve Bazyl <[email protected]>
1 parent 7cee1c2 commit 69f801b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

advanced/driveLabels.gs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// [START apps_script_drive_labels_list_labels]
18+
/**
19+
* List labels available to the user.
20+
*/
21+
function listLabels() {
22+
let pageToken = null;
23+
let labels = [];
24+
do {
25+
try {
26+
const response = DriveLabels.Labels.list({publishedOnly: true, pageToken: pageToken})
27+
pageToken = response.nextPageToken;
28+
labels = labels.concat(response.labels);
29+
} catch (err) {
30+
// TODO (developer) - Handle exception
31+
Logger.log('Failed to list labels with error %s', err.message);
32+
}
33+
} while (pageToken != null);
34+
35+
Logger.log('Found %d labels', labels.length);
36+
console.log(labels[0].name)
37+
}
38+
// [END apps_script_drive_labels_list_labels]
39+
 
40+
// [START apps_script_drive_labels_get_label]
41+
/**
42+
* Get a label by name.
43+
*/
44+
function getLabel(labelName) {
45+
try {
46+
const label = DriveLabels.Labels.get(labelName, {view: "LABEL_VIEW_FULL"});
47+
Logger.log("Fetched label with title: '%s' and %d fields.", label.properties.title, label.fields.length);
48+
} catch (err) {
49+
// TODO (developer) - Handle exception
50+
Logger.log('Failed to get label with error %s', err.message);
51+
}
52+
}
53+
// [END apps_script_drive_labels_get_label]

0 commit comments

Comments
 (0)