Skip to content

Commit

Permalink
feat: Add Meet API quickstart, fix typos in others
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrrrl committed Mar 5, 2024
1 parent b6150ea commit b55ab85
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 14 deletions.
2 changes: 1 addition & 1 deletion adminSDK/directory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion adminSDK/reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion adminSDK/reseller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion apps-script/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion calendar/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file compatible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion classroom/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion drive/activity-v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion drive/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion gmail/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file compatible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
1 change: 1 addition & 0 deletions meet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Additional samples can be found at https://github.com/googleapis/google-cloud-node/tree/main/packages/google-apps-meet
106 changes: 106 additions & 0 deletions meet/quickstart/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable camelcase */
// [START meet_quickstart]
const fs = require('fs').promises;
const path = require('path');
const process = require('process');
const {authenticate} = require('@google-cloud/local-auth');
const {SpacesServiceClient} = require('@google-apps/meet').v2;
const { auth } = require('google-auth-library');

Check failure on line 23 in meet/quickstart/index.js

View workflow job for this annotation

GitHub Actions / lint

There should be no space after '{'

Check failure on line 23 in meet/quickstart/index.js

View workflow job for this annotation

GitHub Actions / lint

There should be no space before '}'

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/meetings.space.created'];

// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = path.join(process.cwd(), 'token.json');
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');

/**
* Reads previously authorized credentials from the save file.
*
* @return {Promise<OAuth2Client|null>}
*/
async function loadSavedCredentialsIfExist() {
try {
const content = await fs.readFile(TOKEN_PATH);
const credentials = JSON.parse(content);
return auth.fromJSON(credentials);
} catch (err) {
console.log(err);
return null;
}
}

/**
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
*/
async function saveCredentials(client) {
const content = await fs.readFile(CREDENTIALS_PATH);
const keys = JSON.parse(content);
const key = keys.installed || keys.web;
const payload = JSON.stringify({
type: 'authorized_user',
client_id: key.client_id,
client_secret: key.client_secret,
refresh_token: client.credentials.refresh_token,
});
await fs.writeFile(TOKEN_PATH, payload);
}

/**
* Load or request or authorization to call APIs.
*
*/
async function authorize() {
let client = await loadSavedCredentialsIfExist();
if (client) {
return client;
}
client = await authenticate({
scopes: SCOPES,
keyfilePath: CREDENTIALS_PATH,
});
if (client.credentials) {
await saveCredentials(client);
}
return client;
}

/**
* Creates a new meeting space.
* @param {OAuth2Client} authClient An authorized OAuth2 client.
*/
async function createSpace(authClient) {
const meetClient = new SpacesServiceClient({
authClient: authClient

Check failure on line 94 in meet/quickstart/index.js

View workflow job for this annotation

GitHub Actions / lint

Missing trailing comma
});
// Construct request
const request = {
};

// Run request
const response = await meetClient.createSpace(request);
console.log(`Meet URL: ${response[0].meetingUri}`);
}

authorize().then(createSpace).catch(console.error);
// [END meet_quickstart]
18 changes: 18 additions & 0 deletions meet/quickstart/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "google-meet-nodejs-quickstart",
"version": "1.0.0",
"description": "A simple Node.js command-line application that makes requests to the Google Meet API.",
"private": true,
"dependencies": {
"@google-cloud/local-auth": "^2.1.0",
"@google-apps/meet": "^0.1.0"
},
"devDependencies": {},
"engines": {
"node": ">=14"
},
"scripts": {
"start": "node ."
},
"license": "Apache-2.0"
}
2 changes: 1 addition & 1 deletion people/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion sheets/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion slides/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down
2 changes: 1 addition & 1 deletion tasks/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function loadSavedCredentialsIfExist() {
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
* Serializes credentials to a file compatible with GoogleAuth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise<void>}
Expand Down

0 comments on commit b55ab85

Please sign in to comment.