Skip to content

Commit f25d51c

Browse files
committed
docs: update comments
1 parent beb48c3 commit f25d51c

File tree

92 files changed

+1111
-381
lines changed

Some content is hidden

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

92 files changed

+1111
-381
lines changed

adminSDK/directory/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for the Admin SDK Directory API.
2425
const SCOPES = ['https://www.googleapis.com/auth/admin.directory.user'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Lists the first 10 users in the domain.
2931
*/
3032
async function listUsers() {
33+
// Authenticate with Google and get an authorized client.
3134
const auth = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
3538

39+
// Create a new Admin SDK Directory API client.
3640
const service = google.admin({version: 'directory_v1', auth});
41+
// Get the list of users.
3742
const result = await service.users.list({
3843
customer: 'my_customer',
3944
maxResults: 10,
@@ -46,6 +51,7 @@ async function listUsers() {
4651
return;
4752
}
4853

54+
// Print the primary email and full name of each user.
4955
console.log('Users:');
5056
users.forEach((user) => {
5157
console.log(`${user.primaryEmail} (${user.name?.fullName})`);

adminSDK/reports/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for the Admin SDK Reports API.
2425
const SCOPES = ['https://www.googleapis.com/auth/admin.reports.audit.readonly'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Lists the last 10 login events for the domain.
2931
*/
3032
async function listLoginEvents() {
33+
// Authenticate with Google and get an authorized client.
3134
const auth = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
38+
39+
// Create a new Admin SDK Reports API client.
3540
const service = google.admin({version: 'reports_v1', auth});
41+
// Get the list of login events.
3642
const result = await service.activities.list({
3743
userKey: 'all',
3844
applicationName: 'login',
@@ -44,6 +50,7 @@ async function listLoginEvents() {
4450
return;
4551
}
4652

53+
// Print the time, email, and event name of each login event.
4754
console.log('Logins:');
4855
activities.forEach((activity) => {
4956
console.log(

adminSDK/reseller/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for the Admin SDK Reseller API.
2425
const SCOPES = ['https://www.googleapis.com/auth/apps.order'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Lists the first 10 subscriptions you manage.
2931
*/
3032
async function listSubscriptions() {
33+
// Authenticate with Google and get an authorized client.
3134
const auth = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
3538

39+
// Create a new Admin SDK Reseller API client.
3640
const service = google.reseller({version: 'v1', auth});
41+
// Get the list of subscriptions.
3742
const result = await service.subscriptions.list({
3843
maxResults: 10,
3944
});
@@ -43,6 +48,7 @@ async function listSubscriptions() {
4348
return;
4449
}
4550

51+
// Print the customer ID, SKU ID, and plan name of each subscription.
4652
console.log('Subscriptions:');
4753
subscriptions.forEach(({customerId, skuId, plan}) => {
4854
console.log(`${customerId} (${skuId}, ${plan?.planName})`);

apps-script/execute/index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,47 @@ import {GoogleAuth} from 'google-auth-library';
2020
import {google} from 'googleapis';
2121

2222
/**
23-
* Call an Apps Script function to list the folders in the user's root Drive
24-
* folder.
23+
* Calls an Apps Script function to list the folders in the user's root Drive folder.
2524
*/
2625
async function callAppsScript() {
26+
// The ID of the Apps Script project to call.
2727
const scriptId = '1xGOh6wCm7hlIVSVPKm0y_dL-YqetspS5DEVmMzaxd_6AAvI-_u8DSgBT';
2828

29-
// Get credentials and build service
30-
// TODO (developer) - Use appropriate auth mechanism for your app
29+
// Authenticate with Google and get an authorized client.
30+
// TODO (developer): Use an appropriate auth mechanism for your app.
3131
const auth = new GoogleAuth({
3232
scopes: 'https://www.googleapis.com/auth/drive',
3333
});
34+
35+
// Create a new Apps Script API client.
3436
const script = google.script({version: 'v1', auth});
35-
// Make the API request. The request object is included here as 'resource'.
37+
3638
const resp = await script.scripts.run({
3739
auth,
3840
requestBody: {
41+
// The name of the function to call in the Apps Script project.
3942
function: 'getFoldersUnderRoot',
4043
},
4144
scriptId,
4245
});
4346

4447
if (resp.data.error?.details?.[0]) {
4548
// The API executed, but the script returned an error.
46-
47-
// Extract the first (and only) set of error details. The values of this
48-
// object are the script's 'errorMessage' and 'errorType', and an array of
49-
// stack trace elements.
49+
// Extract the error details.
5050
const error = resp.data.error.details[0];
51-
5251
console.log(`Script error message: ${error.errorMessage}`);
5352
console.log('Script error stacktrace:');
5453

5554
if (error.scriptStackTraceElements) {
56-
// There may not be a stacktrace if the script didn't start executing.
55+
// Log the stack trace.
5756
for (let i = 0; i < error.scriptStackTraceElements.length; i++) {
5857
const trace = error.scriptStackTraceElements[i];
5958
console.log('\t%s: %s', trace.function, trace.lineNumber);
6059
}
6160
}
6261
} else {
63-
// The structure of the result depends on the Apps Script function's return value.
64-
// Here, the function returns an object with string keys and values, which is
65-
// treated as a Node.js object (folderSet).
62+
// The script executed successfully.
63+
// The structure of the response depends on the Apps Script function's return value.
6664
const folderSet = resp.data.response ?? {};
6765
if (Object.keys(folderSet).length === 0) {
6866
console.log('No folders returned!');

calendar/quickstart/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for reading calendar events.
2425
const SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Lists the next 10 events on the user's primary calendar.
2931
*/
3032
async function listEvents() {
33+
// Authenticate with Google and get an authorized client.
3134
const auth = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
3538

39+
// Create a new Calendar API client.
3640
const calendar = google.calendar({version: 'v3', auth});
41+
// Get the list of events.
3742
const result = await calendar.events.list({
3843
calendarId: 'primary',
3944
timeMin: new Date().toISOString(),
@@ -48,6 +53,7 @@ async function listEvents() {
4853
}
4954
console.log('Upcoming 10 events:');
5055

56+
// Print the start time and summary of each event.
5157
for (const event of events) {
5258
const start = event.start?.dateTime ?? event.start?.date;
5359
console.log(`${start} - ${event.summary}`);

chat/quickstart/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,38 @@ import process from 'node:process';
2121
import {ChatServiceClient} from '@google-apps/chat';
2222
import {authenticate} from '@google-cloud/local-auth';
2323

24+
// The scope for reading Chat spaces.
2425
const SCOPES = ['https://www.googleapis.com/auth/chat.spaces.readonly'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
28-
* Lists spaces with user credential.
30+
* Lists the spaces that the user is a member of.
2931
*/
3032
async function listSpaces() {
33+
// Authenticate with Google and get an authorized client.
3134
const authClient = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
3538

36-
// Create a client
39+
// Create a new Chat API client.
3740
const chatClient = new ChatServiceClient({
3841
authClient,
3942
scopes: SCOPES,
4043
});
4144

42-
// Initialize request argument(s)
45+
// The request to list spaces.
4346
const request = {
44-
// Filter spaces by space type (SPACE or GROUP_CHAT or DIRECT_MESSAGE)
47+
// Filter spaces by type. In this case, we are only interested in "SPACE" type.
4548
filter: 'space_type = "SPACE"',
4649
};
4750

48-
// Make the request
51+
// Make the API request.
4952
const pageResult = chatClient.listSpacesAsync(request);
5053

51-
// Handle the response. Iterating over pageResult will yield results
52-
// and resolve additional pages automatically.
54+
// Process the response.
55+
// The `pageResult` is an async iterable that will yield each space.
5356
for await (const response of pageResult) {
5457
console.log(response);
5558
}

classroom/quickstart/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for reading Classroom courses.
2425
const SCOPES = ['https://www.googleapis.com/auth/classroom.courses.readonly'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Lists the first 10 courses the user has access to.
2931
*/
3032
async function listCourses() {
33+
// Authenticate with Google and get an authorized client.
3134
const auth = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
38+
39+
// Create a new Classroom API client.
3540
const classroom = google.classroom({version: 'v1', auth});
41+
// Get the list of courses.
3642
const result = await classroom.courses.list({
3743
pageSize: 10,
3844
});
@@ -42,6 +48,7 @@ async function listCourses() {
4248
return;
4349
}
4450
console.log('Courses:');
51+
// Print the name and ID of each course.
4552
courses.forEach((course) => {
4653
console.log(`${course.name} (${course.id})`);
4754
});

docs/quickstart/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,29 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for reading Google Docs.
2425
const SCOPES = ['https://www.googleapis.com/auth/documents.readonly'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Prints the title of a sample doc:
2931
* https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
3032
*/
3133
async function printDocTitle() {
34+
// Authenticate with Google and get an authorized client.
3235
const auth = await authenticate({
3336
scopes: SCOPES,
3437
keyfilePath: CREDENTIALS_PATH,
3538
});
39+
40+
// Create a new Docs API client.
3641
const docs = google.docs({version: 'v1', auth});
42+
// Get the document.
3743
const result = await docs.documents.get({
3844
documentId: '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE',
3945
});
46+
// Print the title of the document.
4047
console.log(`The title of the document is: ${result.data.title}`);
4148
}
4249

drive/activity-v2/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,38 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for reading Drive activity.
2425
const SCOPES = ['https://www.googleapis.com/auth/drive.activity.readonly'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Lists the recent activity in your Google Drive.
2931
*/
3032
async function listDriveActivity() {
33+
// Authenticate with Google and get an authorized client.
3134
const auth = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
38+
39+
// Create a new Drive Activity API client.
3540
const service = google.driveactivity({version: 'v2', auth});
41+
42+
// The parameters for the activity query.
3643
const params = {
3744
pageSize: 10,
3845
};
46+
47+
// Query for recent activity.
3948
const result = await service.activity.query({requestBody: params});
4049
const activities = result.data.activities;
4150
if (!activities || activities.length === 0) {
4251
console.log('No activity.');
4352
return;
4453
}
4554
console.log('Recent activity:');
46-
55+
// Print the recent activity.
4756
console.log(JSON.stringify(activities, null, 2));
4857
}
4958

drive/quickstart/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,36 @@ import process from 'node:process';
2121
import {authenticate} from '@google-cloud/local-auth';
2222
import {google} from 'googleapis';
2323

24+
// The scope for reading file metadata.
2425
const SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly'];
26+
// The path to the credentials file.
2527
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
2628

2729
/**
2830
* Lists the names and IDs of up to 10 files.
2931
*/
3032
async function listFiles() {
33+
// Authenticate with Google and get an authorized client.
3134
const auth = await authenticate({
3235
scopes: SCOPES,
3336
keyfilePath: CREDENTIALS_PATH,
3437
});
3538

39+
// Create a new Drive API client.
3640
const drive = google.drive({version: 'v3', auth});
41+
// Get the list of files.
3742
const result = await drive.files.list({
3843
pageSize: 10,
3944
fields: 'nextPageToken, files(id, name)',
4045
});
4146
const files = result.data.files;
42-
if (!files) {
47+
if (!files || files.length === 0) {
4348
console.log('No files found.');
4449
return;
4550
}
4651

4752
console.log('Files:');
53+
// Print the name and ID of each file.
4854
files.forEach((file) => {
4955
console.log(`${file.name} (${file.id})`);
5056
});

0 commit comments

Comments
 (0)