Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用googleapis calendar.calendarList.insert时未找到错误_Javascript_Node.js_Google Api_Google Calendar Api - Fatal编程技术网

Javascript 使用googleapis calendar.calendarList.insert时未找到错误

Javascript 使用googleapis calendar.calendarList.insert时未找到错误,javascript,node.js,google-api,google-calendar-api,Javascript,Node.js,Google Api,Google Calendar Api,我有一个从云函数调用的函数,它应该在服务帐户下创建一个新的日历 它只是在承诺中被调用,电子邮件作为ID参数传递 const { google } = require('googleapis'); const auth = require('./getAuth')(); const calendar = google.calendar('v3'); module.exports = function createCalendar( id) { return new Promise(asyn

我有一个从云函数调用的函数,它应该在服务帐户下创建一个新的日历

它只是在承诺中被调用,电子邮件作为ID参数传递

const { google } = require('googleapis');
const auth =  require('./getAuth')();
const calendar = google.calendar('v3');

module.exports = function createCalendar( id) {
  return new Promise(async (resolve, reject) => {
    const authClient = auth.getClient();
    calendar.calendarList.insert(
      {
        auth: authClient,
        resource: {
          id,
        },
      },
      (err, res) => {
        if (err) {
          console.error('Error creating calendar', err);
          reject(err);
        } else {
          console.info('Successfully created calendar', res.data);
          resolve(res.data);
        }
      }
    );
  });
}
它会导致如下错误:

{ Error: Not Found
    at Gaxios.request (/srv/node_modules/gaxios/build/src/gaxios.js:70:23)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
  response: 
   { config: 
      { url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList?id=wew%40wew.com',
        method: 'POST',
        paramsSerializer: [Function],
        data: [Object],
        headers: [Object],
        params: [Object],
        validateStatus: [Function],
        retry: true,
        body: '{"id":"jdynsy@vananaz.com"}',
        responseType: 'json',
        retryConfig: [Object] },
     data: { error: [Object] },
     headers: 
      { 'alt-svc': 'quic=":443"; ma=2592000; v="46,43,39"',
        'cache-control': 'private, max-age=0',
        connection: 'close',
        'content-encoding': 'gzip',
        'content-type': 'application/json; charset=UTF-8',
        date: 'Mon, 22 Jul 2019 10:44:33 GMT',
        expires: 'Mon, 22 Jul 2019 10:44:33 GMT',
        server: 'GSE',
        'transfer-encoding': 'chunked',
        vary: 'Origin, X-Origin',
        'x-content-type-options': 'nosniff',
        'x-frame-options': 'SAMEORIGIN',
        'x-xss-protection': '1; mode=block' },
     status: 404,
     statusText: 'Not Found' },
  config: 
   { url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList?id=wew%40wew.com',
     method: 'POST',
     paramsSerializer: [Function],
     data: { id: 'wew@wew.com' },
     headers: 
      { ////},
     validateStatus: [Function],
     retry: true,
     body: '{"id":"wew@wew.com"}',
     responseType: 'json',
     retryConfig: 
      { currentRetryAttempt: 0,
        retry: 3,
        retryDelay: 100,
        httpMethodsToRetry: [Array],
        noResponseRetries: 2,
        statusCodesToRetry: [Array] } },
  code: 404,
  errors: 
   [ { domain: 'global', reason: 'notFound', message: 'Not Found' } ] }
{错误:找不到
根据Gaxios.request(/srv/node_modules/Gaxios/build/src/Gaxios.js:70:23)
在
在进程中。_tickDomainCallback(internal/process/next_tick.js:229:7)
答复:
{config:
{url:'https://www.googleapis.com/calendar/v3/users/me/calendarList?id=wew%40wew.com',
方法:“POST”,
参数化器:[函数],
数据:[对象],
标题:[对象],
参数:[对象],
validateStatus:[函数],
重试:true,
正文:“{id”:”jdynsy@vananaz.com"}',
responseType:'json',
retryConfig:[对象]},
数据:{错误:[对象]},
标题:
{'alt svc':'quic=“:443”;ma=2592000;v=“46,43,39”,
“缓存控制”:“专用,最大年龄=0”,
连接:“关闭”,
“内容编码”:“gzip”,
“内容类型”:“应用程序/json;字符集=UTF-8”,
日期:“2019年7月22日星期一10:44:33 GMT”,
到期日期:“2019年7月22日星期一10:44:33 GMT”,
服务器:“GSE”,
“传输编码”:“分块”,
更改:“原点,X原点”,
“x-content-type-options”:“nosniff”,
“x-frame-options”:“SAMEORIGIN”,
“x-xss-protection”:“1;模式=块”},
现状:404,
statusText:'未找到'},
配置:
{url:'https://www.googleapis.com/calendar/v3/users/me/calendarList?id=wew%40wew.com',
方法:“POST”,
参数化器:[函数],
数据:{id:'wew@wew.com' },
标题:
{ ////},
validateStatus:[函数],
重试:true,
正文:“{id”:”wew@wew.com"}',
responseType:'json',
retryConfig:
{CurrentRetryAttest:0,
重试:3,
retryDelay:100,
httpMethodsToRetry:[数组],
无责任者:2,
statusCodesToRetry:[数组]}},
代码:404,
错误:
[{域:'global',原因:'notFound',消息:'notFound'}]}
我找不到任何关于calendarList使用的好文档。请插入任何地方,我希望有人能指出我在实施过程中哪里出了问题?

您是否尝试过以下方法:

const calendar = google.calendar({version:"v3"}).calendarList.insert({
      auth,
      requestBody:{
        id:"dffdsfsd"
      }

    })

这是这一行的包装,你有没有试着取出末尾的()

const auth =  require('./getAuth')();
去掉末尾的(),auth应该是从“getAuth”文件导出的默认模块

const auth =  require('./getAuth');
const calendar = google.calendar('v3');
我在async await中重新编写了下面的代码,因为如果您有多个承诺,承诺可能会非常嵌套

id是否在对象中传递?id必须是日历作为资源插入的对象。calendarList.insert()的参数与events.insert()略有不同


您是否使用模拟模式进行身份验证?什么是模拟模式?
const auth =  require('./getAuth');
const calendar = google.calendar('v3');
module.exports = async function createCalendar(id) {
  try {
    const authClient = auth.getClient();
    const res = await calendar.calendarList.insert({ auth: authClient, resource: id })
    // insert returns an object that has a data property that includes the event you inserted
    console.info('Successfully created calendar', res.data);
  } catch (err) {
    console.error('Error creating calendar', err)
  }
}