简体   繁体   中英

Empty title when inserting a Google Task with google apis node.js client

When I use this code, a new task is created but the title is empty

const service = google.tasks({ version: "v1", auth })
service.tasks.insert(
    {
        tasklist: <ID_OF_YOUR_TASK_LIST>,
        title: "hello"

    },
    (err, res) => {
        if (err) return console.error(err)
        console.log(res)
    }
)

You can use resource instead of requestBody , it will work too.

Tested on Node 13.4.0, works as expected

function insertTask(auth) {
  const service = google.tasks({version: 'v1', auth});
  service.tasks.insert({
    "tasklist": "___ID___",
    "resource": {
      "title": "___TITLE___"
    }
  }, (err, res) => {
    if (err) return console.error('The API returned an error: ' + err);
  });
}

Reference

Google Tasks API > Tasks > insert

I found after a while that you need to specify body parameters in a requestBody object. The code below is working

const service = google.tasks({ version: "v1", auth })
service.tasks.insert(
    {
        tasklist: <ID_OF_YOUR_TASK_LIST>,,
        requestBody: { // ! important !
            title: "hello"
        }
    },
    (err, res) => {
        if (err) return console.error(err)
        console.log(res)
    }
)

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