google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Docs on developers.google.com are out of date for Google Drive

Open DominikPalo opened this issue 6 years ago • 14 comments

Environment details

  • OS: Windows 10
  • Node.js version: 10.16.0
  • npm version: 6.9.0
  • googleapis version: 45.0.0

I'm trying to import a PowePoint file to Google Drive as a Google Docs document (see https://developers.google.com/drive/api/v3/manage-uploads#import_to_google_docs_types_), but drive.files.create doesn't accept the resource option. When I try to pass fileMetadata as:

const fileMetadata = {
  name: 'PowerPoint_test',
  mimeType: 'application/vnd.google-apps.presentation'
};

const media = {
  mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  body: fs.createReadStream('files/test.ppt')
};

drive.files.create({
  resource: fileMetadata,
  media: media,
  fields: 'id'
}, (err, file) => {
  if (err) {
    // Handle error
    console.error(err);
  } else {
    console.log('File Id:', file.id);
  }
});

it shows an error:

Object literal may only specify known properties, and 'resource' does not exist in type 'Params$Resource$Files$Create'.

DominikPalo avatar Nov 21 '19 13:11 DominikPalo

Greetings! Instead of resource, you want to use requestBody with the same contents:

const fileMetadata = {
  name: 'PowerPoint_test',
  mimeType: 'application/vnd.google-apps.presentation'
};

const media = {
  mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  body: fs.createReadStream('files/test.ppt')
};

drive.files.create({
  requestBody: fileMetadata,
  media: media,
  fields: 'id'
}, (err, file) => {
  if (err) {
    // Handle error
    console.error(err);
  } else {
    console.log('File Id:', file.id);
  }
});

JustinBeckwith avatar Dec 02 '19 03:12 JustinBeckwith

@erickoledadevrel @sqrrrl Looks like the samples on that page are linked in from gerrit. Any way we could get these using the samples on https://github.com/gsuitedevs/node-samples/?

@grant I know this ain't your game anymore, but your thoughts would be awesome here too :)

JustinBeckwith avatar Dec 02 '19 04:12 JustinBeckwith

Thank you, it works with requestBody.

Also, there is another small issue: The ID of the uploaded file is accessible via file.data.id (not via file.id as in the example).

DominikPalo avatar Dec 02 '19 14:12 DominikPalo

This is still an issue, pages such as https://developers.google.com/drive/api/v3/manage-uploads still cite resource. The only place that mentions this is the way to fix it is these issue reports (Stack Overflow answers all still use resource). Very frustrating because you have to find this first!

TaylorDale avatar Apr 17 '20 03:04 TaylorDale

We still suffer from this. I've been struggling to use the APIs because the code samples don't match what we really have in this client library. The samples are cool, but unfortunately, they don't cover too many usage cases.

Luckily we can go over most of the mismatches because the docs in the client code itself help a lot. Still, having completely different versions of official docs and client one is really annoying.

To make it even worse, Google Drive's docs are not the only ones outdated. Sheet's one also suffers from the same problem.

StanleySathler avatar Jul 01 '20 21:07 StanleySathler

Further, it seems like a large number of stack-overflow questions related to the api point to now lost pages, across 2/3 different ways of viewing Google's own api docs- finding correct documentation is rough, to say the least.

Go2ClassPoorYorick avatar Jul 23 '20 21:07 Go2ClassPoorYorick

I'm so sorry about the documentation mess. Looking at the docs, it's still not fixed. I'm going to surface this to the responsible team.

fhinkel avatar Dec 07 '20 09:12 fhinkel

Internal b/144911539

fhinkel avatar Dec 07 '20 10:12 fhinkel

Still a problem!

asktree avatar May 05 '21 15:05 asktree

Still a problem 2 years later.

bcla22 avatar Mar 31 '22 20:03 bcla22

Still an issue - example here from shared drive creation docs

etekweb avatar Jul 07 '23 14:07 etekweb