将事件插入到谷歌日历中会出现错误404"未找到"

时间:2017-07-24 07:39:21

标签: node.js express google-calendar-api

我正在创建一个Node JS(Express)网络应用,一旦用户登录并在我的数据库中将事件事件插入谷歌日历,就会显示用户的Google日历活动。

我正在尝试通过带有服务帐户的Google Calendar API插入事件

我使用的代码:

var   googleapis = require("googleapis"),
    googleCal = googleapis.calendar("v3"),
    serviceEmail = "*****@*******gserviceaccount.com",
    serviceKeyFile = "./key.p12";

var authClient = new googleapis.auth.JWT(
        serviceEmail,
        serviceKeyFile,
        null,
        ["https://www.googleapis.com/auth/calendar"]
    );

authClient.authorize(function (err, tokens) {
  console.log("tokens"+JSON.stringify(tokens));
    if (err) {
        console.log(err);
    } else {
        googleCal.events.list({
            auth: authClient,
            calendarId: "*********@gmail.com",
            fields: {
                items: ["end","start","summary"]
            }
        }, function (err, CL) {
            if (err) {
                console.log(err);
            } else {
                console.log("calendar"+CL);
            }
        });
    }
})
var event = {
  'summary': 'Google I/O 2015',
  'location': '800 Howard St., San Francisco, CA 94103',
  'description': 'A chance to hear more about Google\'s developer products.',
  'start': {
    'dateTime': '2017-07-28T09:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'end': {
    'dateTime': '2017-07-28T17:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'recurrence': [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  'attendees': [
    {'email': 'lpage@example.com'},
    {'email': 'sbrin@example.com'},
  ],
  'reminders': {
    'useDefault': false,
    'overrides': [
      {'method': 'email', 'minutes': 24 * 60},
      {'method': 'popup', 'minutes': 10},
    ],
  },
};
googleCal.events.insert({
    auth: authClient,
    calendarId:'primary',
     resource: event,
}, function (err, events) {
    if (err) {
        console.log("there is an error"+err);
    } else {
        console.log(events);
        console.log("events are created successfully");
    }
})

我的问题是在执行时显示错误,如

  

{错误:未找到       在Request._callback(D:\ studentportal \ node_modules \ google-auth-library \ lib \ transporters.js:85:15)       在Request.self.callback(D:\ studentportal \ node_modules \ request \ request.js:186:22)       在emitTwo(events.js:106:13)       在Request.emit(events.js:191:7)       在请求。 (d:\ studentportal \ node_modules \请求\ request.js:1081:10)       在emitOne(events.js:96:13)       在Request.emit(events.js:188:7)       在IncomingMessage。 (d:\ studentportal \ node_modules \请求\ request.js:1001:12)       在IncomingMessage.g(events.js:291:16)       在emitNone(events.js:91:20)       在IncomingMessage.emit(events.js:185:7)       at endReadableNT(_stream_readable.js:974:12)       at _combinedTickCallback(internal / process / next_tick.js:74:11)       at process._tickCallback(internal / process / next_tick.js:98:9)代码:404,错误:[{domain:' global&#39 ;, reason:' notFound',   消息:'未找到' }]}

这是什么解决方案?

1 个答案:

答案 0 :(得分:0)

尝试检查一下,希望它可以帮助您Handle API Error: 404

  

404:未找到

     

找不到指定的资源。这可能发生在几个   案例。以下是一些例子:

     

当所请求的资源(具有提供的ID)从未存在时   访问用户无法访问的日历时

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}