I am creating an application using asp.net mvc<\/code> and
javascript<\/code> in which I want to create folders inside my existing google drive folder.
function createFolder() {
var body = {
'title': document.getElementById('txtFolderName').value,
'mimeType': "application/vnd.google-apps.folder"
};
var request = gapi.client.drive.files.insert({
'resource': body
});
request.execute(function (resp) {
console.log('Folder ID: ' + resp.id);
});
}
I thought that in your script, https:\/\/docs.googleapis.com\/$discovery\/rest?version=v1<\/code> of
gapi.client.load("https:\/\/docs.googleapis.com\/$discovery\/rest?version=v1")<\/code> is used for Google Docs API v1.
I think that the reason for your error message of
Uncaught TypeError: Cannot read properties of undefined (reading 'files')<\/code> is due to this.
In this case, please use Drive API. But, when I saw your current script for creating the folder, Drive API v2 is used. So, please modify as follows.
<\/h3><\/h3> return gapi.client.load("https:\/\/www.googleapis.com\/discovery\/v1\/apis\/drive\/v2\/rest")<\/code><\/pre>
By this modification, I thought that your createFolder()<\/code> works.
But in your current createFolder()<\/code> , the folder is created to the root folder.
When you want to create the folder into a specific folder, please modify the request body as follows.
<\/h3>
As additional information, if you want to use Drive API v3, please modify it as follows.
<\/h3>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.