-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Meet API quickstart, fix typos in others
- Loading branch information
Showing
17 changed files
with
139 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
||
|
||
// 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 | ||
}); | ||
// 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters