简体   繁体   English

使用 google apis node.js 客户端插入 Google 任务时标题为空

[英]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.您可以使用resource而不是requestBody ,它也可以工作。

Tested on Node 13.4.0, works as expected在 Node 13.4.0 上测试,按预期工作

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 Google Tasks API > 任务 > 插入

I found after a while that you need to specify body parameters in a requestBody object.一段时间后,我发现您需要在requestBody对象中指定 body 参数。 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)
    }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.js中的Google API - Google APIs in Node.js 尝试使用Google API Node.js客户端时出现“找不到模块”错误 - Getting “Module not found” error when trying to use the Google APIs Node.js client 使用googleapis node.js api(google-api-nodejs-client)插入google plus moment - Inserting google plus moment using googleapis node.js api (google-api-nodejs-client) 如何在Node.js中发现Google OAuth2中的API - How to discover APIs in Google OAuth2 in Node.js 谷歌api + node.js +谷歌api-nodejs-client - google api + node.js + google-api-nodejs-client Node.js - Google 日历 API 在插入事件时显示错误“缺少结束时间” - Node.js - Google Calendar API showing error "Missing end time" when inserting an event 如何使用 Google-sheet-apis(Node.js) 从 google-sheet 中获取特定行? - How to fetch Specific row from google-sheet by using Google-sheet-apis(Node.js)? 尝试在Node JS中初始化Google Cloud API时Serverless失败 - Serverless is failing when trying to initialize google cloud apis in node js 使用TypeScript时,扩展Node.js客户端库中的“ conv”实例以在Google v2上执行操作 - Extend “conv” instance in Node.js Client Library for Actions on Google v2 when using TypeScript 如何使用 Node.js 以编程方式从 Google 任务队列中删除 Google 任务? - How to delete Google task from Google Task queue programmatically using Node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM