Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
authClient.request is not a function problem

I followed several hundred links, most including stackoverflow links, to try to come up with a solution to this problem, but none yielded results.

I am simply trying to get the server to access client's detail via google. Ie, get the client's Google Sheets. I followed their documentation, but for the most part, its on client side only. I followed the instructions for server-side, but it has uncompleted work in it. I found out that the method to do is to have the client sign in via OAuth2.0 and then send the recieved code to the server to process to its very own access code. That is what I'm doing, however, when I try to query any data, I get that error in the title. Here is the code snippets, please let me know if there's anything I'm missing. RIP my rep.

server:

const Router=require("express").Router()
const auth=require("../utils/auth")
const fs= require("fs")
const {OAuth2Client}=require("google-auth-library")//I tried with this library instead, and it will give the exact same error.
const {google} = require('googleapis');
var auths=[]
function oAuth2ClientGetToken(oAuth2Client, code) {
    return new Promise((resolve, reject) => {
      oAuth2Client.getToken(code, (err, token) => { // errors out here
        if (err) reject(err);
        resolve(token);
      });
    });
}
async function formAuthClient(code) {
    const {client_secret, client_id,redirect_uris}  = JSON.parse(fs.readFileSync(__dirname+"/credentials.json"))
    const oAuth2Client = new google.auth.OAuth2( // form authObject
        client_id, client_secret,redirect_uris[1]
    );
    // var oauth2Client = new OAuth2Client(client_id,client_secret,redirect_uris[1]); other method
    const token = await oAuth2ClientGetToken(oAuth2Client, code).catch(console.err);
    // oauth2Client.credentials=token other method of oauth2.0
    oAuth2Client.setCredentials(token);
    return oAuth2Client;
}

Router.get("/",(req,res)=>{
    res.render("home")
})
Router.post("/sheet",async (req,res)=>{
    try {
        const requestBody = {
            properties: {
                title:"hello"
            }
        };
        var sheets= google.sheets({version:"v4", auth: auths[req.session.id]})
        await sheets.spreadsheets.create(requestBody)
    } catch (error) {
        res.json(error)
    }
})
Router.post("/login",(req,res)=>{
    console.log("token: ",req.body.token);
    req.session.token=req.body.token
    console.log("req.session.id:",req.session.id);
    auths[req.session.id]=formAuthClient(req.body.token)
    res.status(200).json()
})


module.exports=Router

the client scripts is a simple button that will trigger an "getOfflineAccess" command and ask the user to log in and then send that data to the server with "/login". then, once another button is pushed, it will call "/sheet". I appreciate all help with this. I ran out of links to click on trying to solve this problem

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda