-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreateFolder.js
42 lines (36 loc) · 947 Bytes
/
createFolder.js
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
const { google } = require("googleapis");
require("dotenv").config();
console.log(process.env.CRED_FILE_PATH);
const SCOPES = ["https://www.googleapis.com/auth/drive"];
const auth = new google.auth.GoogleAuth({
keyFile: process.env.CRED_FILE_PATH,
scopes: SCOPES,
});
const driveService = google.drive({ version: "v3", auth });
const fileMetaData = {
name: "test-images",
mimeType: "application/vnd.google-apps.folder",
};
driveService.files
.create({
resource: fileMetaData,
fields: "id",
})
.then((response) => {
console.log(response);
console.log(response.data.id);
setPermission(response.data.id);
})
.catch((err) => console.log(err));
const setPermission = (fileId) => {
driveService.permissions
.create({
fileId: fileId,
requestBody: {
role: "reader",
type: "anyone",
},
})
.then((res) => console.log(res))
.catch((err) => console.log(err));
};