Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!