I have been trying to create a folder with a service account using google drive APIs in google drive. I can see that folder in the google folder list API but not in the google drive GUI.
Here is the code which I tried to create a google drive folder
const { google } = require('googleapis');
require('dotenv').config();
const CREDENTIALS_PATH = process.env.CREDENTIALS_PATH
const scopes = ['https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive']
module.exports = {
createFolder: async () => {
const auth = new google.auth.GoogleAuth({
scopes: scopes,
keyFilename: CREDENTIALS_PATH
})
const service = google.drive({ version: 'v3', auth: auth });
const fileMetadata = {
name: 'newFolder',
mimeType: 'application/vnd.google-apps.folder'
};
try {
const file = await service.files.create({
requestBody: fileMetadata,
fields: 'id',
});
if (!file.data.id) return;
const res2 = await service.permissions
.create({
resource: {
role: "owner",
type: "user",
emailAddress: email,
},
fileId: file.data.id,
transferOwnership: true,
supportsAllDrives: true
}).catch((err) => console.log(err));
console.log(res2.data);
return file.data.id;
} catch (err) {
throw err;
}
}
}
When I give permission to open a folder in drive then it throws an error.
Please find the below error:
GaxiosError: Bad Request. User message: "You cannot share this item because it has been flagged as
response: {
config: {
url: 'https://www.googleapis.com/drive/v3/files/15NJCr03yIXZ5Sv-xwK3ZiuW0UFTIk4IM/permissions?fields=%2A&transferOwnership=true&moveToNewOwnersRoot=true',
method: 'POST',
userAgentDirectives: [Array],
paramsSerializer: [Function (anonymous)],
data: [Object],
headers: [Object],
params: [Object],
validateStatus: [Function (anonymous)],
retry: true,
body: '{"type":"user","role":"owner","emailAddress":"########"}',
responseType: 'json',
retryConfig: [Object]
},
data: { error: [Object] },
headers: {
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
'cache-control': 'private, max-age=0',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
server: 'ESF',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '0'
},
status: 400,
statusText: 'Bad Request',
request: {
responseURL: 'https://www.googleapis.com/drive/v3/files/15NJCr03yIXZ5Sv-xwK3ZiuW0UFTIk4IM/permissions?fields=%2A&transferOwnership=true&moveToNewOwnersRoot=true'
}
},
config: {
url: 'https://www.googleapis.com/drive/v3/files/15NJCr03yIXZ5Sv-xwK3ZiuW0UFTIk4IM/permissions?fields=%2A&transferOwnership=true&moveToNewOwnersRoot=true',
method: 'POST',
userAgentDirectives: [ [Object] ],
paramsSerializer: [Function (anonymous)],
data: {
type: 'user',
role: 'owner',
emailAddress: '#########'
},
headers: {
'x-goog-api-client': 'gdcl/6.0.3 gl-node/18.5.0 auth/8.7.0',
'Accept-Encoding': 'gzip',
'User-Agent': 'google-api-nodejs-client/6.0.3 (gzip)',
Authorization: 'Bearer #############################################',
'Content-Type': 'application/json',
Accept: 'application/json'
},
params: { fields: '*', transferOwnership: true, moveToNewOwnersRoot: true },
validateStatus: [Function (anonymous)],
retry: true,
body: '{"type":"user","role":"owner","emailAddress":"##############"}',
responseType: 'json',
retryConfig: {
currentRetryAttempt: 0,
retry: 3,
httpMethodsToRetry: [Array],
noResponseRetries: 2,
statusCodesToRetry: [Array]
}
},
code: 400,
errors: [
{
message: 'Bad Request. User message: "You cannot share this item because it has been flagged as inappropriate."',
domain: 'global',
reason: 'invalidSharingRequest'
}
]
}
Can you please help me to find that folder in google drive using google drive API?