Jonio
Jonio

Reputation: 1293

file.id undefined during creation folder in google drive with api rest

I receive undefined during creation of a folder by api rest google:

Folder Id: undefined

Below my code:

  var fileMetadata = {
    'name': nameProduct,
    'mimeType': 'application/vnd.google-apps.folder',
    parents: XXXXXXXXXXXXXXXX
  };
  drive.files.create({
    auth: jwToken,
    resource: fileMetadata,
    fields: 'id'
  }, function (err, file) {
    if (err) {
      console.error(err);
    } else {
      console.log('Folder Id: ', file.id);
    }
  });
  console.log("end creation folder");

How can I print the file.id? Thanks

Upvotes: 1

Views: 712

Answers (1)

Kolzar
Kolzar

Reputation: 873

// Make sure the client is loaded and sign-in is complete before calling 
gapi.client.drive.files.create({
    "resource": {}
  })
  .then(function(response) {
    // Handle the results here (response.result has the parsed body).
    console.log("Response", response);
    },
    function(err) { 
      // handle error here.
      console.error("Execute error", err); });
  }

First you have to create a request then wait the response inside the "then".

Upvotes: 1

Related Questions