简体   繁体   中英

Specify request body in Google API calls (using Google APIs Client Library for JavaScript)

I am trying to call Google API method drive.files.insert to create a folder in Google Drive with a request like this (using Google APIs Client Library for JavaScript):

var request = gapi.client.drive.files.insert({'convert': 'false', 'ocr': 'false'});
request.execute(function(resp) { console.log(resp); });

The problem is that I need to specify some params in the request body, for example:

{
    "title":"testFolder",
    "description":"hello world",
    "mimeType":"application/vnd.google-apps.folder"
}

But I cannot figure it out how to specify these parameters with the Google APIs Client Library for JavaScript. Is there any suggestion of how I can achieve this?

Not necessarily gapi.client.request with body field.

You may try gapi.client.drive.files.insert({'convert': 'false', 'ocr': 'false','resource': resource}) where resource is actually what you want to send, eg

resource = {
    "title":"testFolder",
    "description":"hello world",
    "mimeType":"application/vnd.google-apps.folder"
}

I have not verified that but I have tried exactly the same scenario with sending request body for creating Google Task list (gapi.client.tasks.tasklists.insert)

使用“resource”关键字发送正文。

Pass the body field. See this example for more information.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM