browser-samples icon indicating copy to clipboard operation
browser-samples copied to clipboard

Drive API Quickstart broken

Open DustinWehr opened this issue 5 years ago • 5 comments

The file https://github.com/gsuitedevs/browser-samples/blob/master/drive/quickstart/index.html, which is currently hosted at https://developers.google.com/drive/api/v3/quickstart/js. Following the instructions exactly:

  • Authorize with my google account works.
  • The call to listFiles gives 401 error. Likewise if I try to call it from the console.

But it works if I remove the apiKey parameter from the gapi.client.init call.

Didn't know if I should make an issue here or at https://github.com/google/google-api-javascript-client.

JavaScript Console Output

cb=gapi.loaded_0:228 GET https://content.googleapis.com/drive/v3/files?pageSize=10&fields=nextPageToken%2C%20files(id%2C%20name)&key=[MY API KEY DELETED] 401
wh @ cb=gapi.loaded_0:228
g @ cb=gapi.loaded_0:228
xh @ cb=gapi.loaded_0:229
(anonymous) @ cb=gapi.loaded_0:229
d @ cb=gapi.loaded_0:186
b @ cb=gapi.loaded_0:181
cb=gapi.loaded_0:191 Uncaught {result: {…}, body: "{↵ "error": {↵  "errors": [↵   {↵    "domain": "gl…e": 401,↵  "message": "Invalid Credentials"↵ }↵}↵", headers: {…}, status: 401, statusText: null}
(anonymous) @ cb=gapi.loaded_0:191
setTimeout (async)
Aj @ cb=gapi.loaded_0:191
(anonymous) @ cb=gapi.loaded_0:204
Nj @ cb=gapi.loaded_0:196
Promise.then (async)
Ij @ cb=gapi.loaded_0:196
_.Mj @ cb=gapi.loaded_0:196
ek @ cb=gapi.loaded_0:203
_.Oj.kh @ cb=gapi.loaded_0:202
(anonymous) @ cb=gapi.loaded_0:197
d @ cb=gapi.loaded_0:976
(anonymous) @ cb=gapi.loaded_0:974
(anonymous) @ cb=gapi.loaded_0:491
v.__cb @ cb=gapi.loaded_0:431
d @ cb=gapi.loaded_0:425
b @ cb=gapi.loaded_0:420

Specifications

  • Browser (Chrome/Internet Explorer/Firefox): Chrome
  • OS (Mac/Linux/Windows): Linux

DustinWehr avatar Oct 05 '20 16:10 DustinWehr

I can confirm this behaviour, and removing the API_KEY fixed the problem. Many thanks to @DustinWehr for providing a quick solution, though I'm interested in why we don't need the API_KEY anymore...

pileks avatar Nov 17 '20 20:11 pileks

Trying to use the same example and it does not work unless you remove the 'apiKey' parameter as stated by @DustinWehr.

Thank you @DustinWehr

LostBeard avatar Mar 05 '23 15:03 LostBeard

+1 to this, found out the hard way with the Picker quickstart.

TheEgghead27 avatar Apr 24 '23 01:04 TheEgghead27