I have integrated the google drive download and share the file in my website.
A user login in our application with the google-login, we got his authorise scope once he logged-in our website. We are integrated google-chooser for pickup any file from his personal google drive. once he chosen any file eg: sample.pdf we are downloading his file from google drive to our website.we are using below code.
function downloadFile(auth)
{
const drive = google.drive({ version: 'v3', auth });
var fileId = 'Choosen-file-id from google drive';
const dest = fs.createWriteStream('./downloadFiles/12.doc');
try{
drive.files.export({
fileId: fileId,
mimeType: 'application/vnd.google-apps.document'
}, {
responseType: 'stream'
},function(err, response){
if(err)return console.log(err);
response.data.on('error', err => {
console.log(err);
}).on('end', ()=>{
console.log('success');
})
.pipe(dest);
});
}catch(errr)
{
console.log(errr,'downloadFileErr')
}
}
similarly we are sharing any file from our website to logged-in user drive account with below code.
function uploadFile(auth)
{
const drive = google.drive({ version: 'v3', auth });
drive.files.create({
headers: {
'Authorization': 'Bearer Authorize Token received when user loggedIn with google account',
'Content-Type': "image/png",
},
resource: {
'name': `sampledocc`
},
media: {
mimeType:"image/png",
body: fs.createReadStream('./downloadFiles/4.png')
},
fields: 'id'
}, async function (err, file) {
if (err)
{
// Handle error
console.log(err,'Failed to upload');
} else {
console.log(err,'File uploaded successfully');
}
});
}
But we are getting below errors for both sharing and downloading file.
1)Limit exceeded 2)Unauthorized access 3)You have no-permissions 4)Invalid Credentials
We are already added billing details in google cloud account and activated Google Picker API, Google Drive Api and redirection urls and non restricted scope like https://www.googleapis.com/auth/drive.file
But unable to resolve the issue. we asked google oauth team but they are mentioned ask in forums /help. so i posted this in forum. can you please share or sort out the issue.