Skip to content

I am not able to create folder in google drive using google drive APIs #314

Description

@tush009

I have been trying to create a folder with OAuth and a service account using google drive APIs in google drive. I can see that folder in the service account 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();constCREDENTIALS_PATH=process.env.CREDENTIALS_PATHconstscopes=['https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive']module.exports={createFolder: async()=>{constauth=newgoogle.auth.GoogleAuth({scopes: scopes,keyFilename: CREDENTIALS_PATH})constservice=google.drive({version: 'v3',auth: auth});constfileMetadata={name: 'newFolder',mimeType: 'application/vnd.google-apps.folder'};try{constfile=awaitservice.files.create({requestBody: fileMetadata,fields: 'id',});if(!file.data.id)return;constres2=awaitservice.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);returnfile.data.id;}catch(err){throwerr;}}}

When I give permission to open a folder in drive then it throws an error.

Please find the below error:

GaxiosError: BadRequest.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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions