google apis on client side
Unanswered
Filip posted this in #help-forum
FilipOP
Hey I would like to ask, if there is any possible way to use googleapis library on client side in nextjs 13.4. I am trying to log my files from a google drive folder. On server side, it all works perfectly and on client side it keeps throwing error "Module not found: Can't resolve 'fs'" and I saw it might be related to the client x server side thing so I ask you there.. I dont really know how to work with this topic generally so I would like to know if it is even possible to do something like this..
2 Replies
FilipOP
import { google } from "googleapis"
// ...
const oauth2Client = new google.auth.OAuth2(
CLIENT_ID,
CLIENT_SECRET,
REDIRECT_URI
)
oauth2Client.setCredentials({ refresh_token: REFRESH_TOKEN })
const drive = google.drive({
version: "v3",
auth: oauth2Client
})
const readFileFromDirectory = async (directory) => {
try {
const response = await drive.files.list({
q: `'${directory}' in parents`
})
return response.data.files
} catch (error) {
console.log(error)
}
}this is basically the function i would like to use on client side