Docs on developers.google.com are out of date for Google Drive
Environment details
- OS: Windows 10
- Node.js version: 10.16.0
- npm version: 6.9.0
googleapisversion: 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'.
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);
}
});
@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 :)
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).
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!
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.
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.
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.
Internal b/144911539
Still a problem!
Still a problem 2 years later.
Still an issue - example here from shared drive creation docs