首页 文章

将事件插入到Google日历中会出现错误404“NOT FOUND”

提问于
浏览
0

我正在创建一个Node JS(Express)Web应用程序,它将在用户登录后显示用户的Google Calendar事件,并将事件事件从我的数据库插入到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.self.callback(D:\ studentportal \ node_modules \ request \)处的Request._callback(D:\ studentportal \ node_modules \ google-auth-library \ lib \ transporters.js:85:15)中找不到request.js:186:22)在requestTmit(events.js:191:7)的emitTwo(events.js:106:13)处 . (D:\ studentportal \ node_modules \ request \ request.js:1081:10)在发送单上(events.js:96:13),位于IncomingMessage的Request.emit(events.js:188:7) . (D:\ studentportal \ node_modules \ request \ request.js:1001:12)IncomingMessage.g(events.js:291:16)atInputMessage.emit(events.js)的emitNone(events.js:91:20) :185:7)在end_adinedNT(_stream_readable.js:974:12)的_combinedTickCallback(internal / process / next_tick.js:74:11)at process._tickCallback(internal / process / next_tick.js:98:9)代码: 404,错误:[{domain:'global',reason:'notFound',message:'Not Found'}]}

这是什么解决方案?

1 回答

  • 0

    尝试检查这一点,希望它可以帮助你Handle API Error: 404

    404:未找到未找到指定的资源 . 在某些情况下会发生这种情况 . 以下是一些示例:当访问用户无法访问的日历时,所请求的资源(具有提供的ID)从未存在过

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

相关问题