-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (45 loc) · 1.67 KB
/
index.js
File metadata and controls
52 lines (45 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Copyright 2022 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.
*/
// [START docs_quickstart]
import path from 'node:path';
import process from 'node:process';
import {authenticate} from '@google-cloud/local-auth';
import {google} from 'googleapis';
// The scope for reading Google Docs.
const SCOPES = ['https://www.googleapis.com/auth/documents.readonly'];
// The path to the credentials file.
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
/**
* Prints the title of a sample doc:
* https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
*/
async function printDocTitle() {
// Authenticate with Google and get an authorized client.
const auth = await authenticate({
scopes: SCOPES,
keyfilePath: CREDENTIALS_PATH,
});
// Create a new Docs API client.
const docs = google.docs({version: 'v1', auth});
// Get the document.
const result = await docs.documents.get({
documentId: '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE',
});
// Print the title of the document.
console.log(`The title of the document is: ${result.data.title}`);
}
await printDocTitle();
// [END docs_quickstart]