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

191
Visualizações
Google Drive api Error gapi.client.request

Hello guys I am using Google Picker API but when i comes to this code

var request1 =  gapi.client.request({
                        'path': '/drive/v3/files/' + fileID + '/permissions',
                        'method': 'POST',
                        'headers': {
                            'Content-Type': 'application/json',
                            'Authorization': 'Bearer ' + oauthToken
                        },
                        'body': {
                            'role': role,
                            'type': type
                        }
                    });
                    request1.execute(function (resp) {
                        console.log(resp);
                    });

I keep on getting error on gapi.client.request, you see in the image below. I don't what Im doing wrong here I also search alot in the google. And this code is also same with the code that I found in google and I need this to run in my website but I keep getting this error.

Any idea will do thank you. Uncaught TypeError: Cannot read properties of undefined (reading 'request')

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Loading the library takes a bit of time to complete before it is fully loaded. So when you try to use gapi.client.request, gapi.client is still undefined.

Make sure the library is loaded before proceeding.

Sample:

<body>
  Tester2
  <script>
    googleApiClientReady = function () {
      var request1 =  gapi.client.request({
        'path': '/drive/v3/files/' + fileID + '/permissions',
        'method': 'POST',
        'headers': {
          'Content-Type': 'application/json',           
          'Authorization': 'Bearer ' + oauthToken
        },
        'body': {
          'role': role,
          'type': type
        }
      });
      request1.execute(function (resp) {
        console.log(resp);
      });
    }
  </script>
  <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
</body>

Output:

output

Error now proceeds to undefined fileID instead of undefined gapi.client, inferring that the latter is now defined.

Note:

  • If you want to update a file in drive, method should be PATCH not POST. (reference: PATCH vs POST)
about 4 years ago · Juan Pablo Isaza Relatório
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