Specify the request body in Google API calls (using the Google APIs API client library for JavaScript)

I am trying to call the Google API method drive.files.insert to create a folder in Google Drive with the same request (using the Google APIs API 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 parameters in the request body, for example:

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

But I canโ€™t understand how to specify these parameters in the Google API client library for JavaScript. Are there any suggestions on how I can achieve this?

+6
source share
3 answers

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

+3
source

Not necessarily gapi.client.request with the body field.

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

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

I did not check this, but I tried the exact same scenario with sending the request body to create a list of Google tasks (gapi.client.tasks.tasklists.insert)

+5
source

Use the keyword "resource" to send the body.

+4
source

Source: https://habr.com/ru/post/922188/


All Articles