[英]How do I update a google calendar event using Node js?
I'm following the google calendar documentation to update an event via a service account here .我正在按照 google 日历文档通过此处的服务帐户更新事件。 Unfortunately, besides describing the initial setup with node in mind (which still doesn't show the process via a service account) google doesn't seem to include the node flavor in any further documentation.
不幸的是,除了在考虑节点的情况下描述初始设置(它仍然没有通过服务帐户显示过程)之外,谷歌似乎没有在任何进一步的文档中包含节点风格。
My authentication is setup below:我的身份验证设置如下:
//import google library
const {google} = require("googleapis")
//setup scope of auth
const scopes = ['https://www.googleapis.com/auth/calendar.events'];
//load client secrets from a local file
let credentialsRaw = fs.readFileSync(process.env.GOOGLE_CALENDAR_SECRET);
//get credentials as json parsed from raw file contents
let credentials = JSON.parse(credentialsRaw);
//setup auth obj
let auth = new google.auth.JWT(
credentials.client_email, null,
credentials.private_key, scopes
);
Followed by my code that tries to update the event:其次是我尝试更新事件的代码:
//setup calendar object
const calendar = await google.calendar({
version: "v3",
auth
});
//make call to update calendar event
let updateResults = await calendar.events.update({
auth: auth,
calendarId: req.body.calendar_id, //log looks like: i798978asdfjka678sagsdfv3344@group.calendar.google.com
eventId: req.body.event_id, //log looks like: 12432dsfkjhhwqejhkj12
resource: {
"summary": "Test Summary",
"description": "Test Description",
"end": req.body.end_time, //log for end and start look like: { dateTime: '2021-08-09T11:30:00-04:00', timeZone: 'America/New_York' }
"start": req.body.start_time,
}
});
The error I get is "Not found".我得到的错误是“未找到”。 That's it.
而已。 I've tried encoding the calendarId with
encodeURIComponent()
according to this answer but that didn't change anything.我已经尝试根据这个答案使用
encodeURIComponent()
对 calendarId 进行编码,但这并没有改变任何东西。 The poster of that answer also mentioned later that the encoding fix isn't needed anymore.该答案的发布者稍后还提到不再需要编码修复。
Some common issues on the account side I think I've handled correctly:账户方面的一些常见问题我认为我已经正确处理了:
The following should show you how to authorize the service account.下面应该向您展示如何授权服务帐户。
const {google} = require('googleapis');
const auth = new google.auth.GoogleAuth({
keyFile: '/path/to/your-secret-key.json',
scopes: ['https://www.googleapis.com/auth/calendar.events'],
});
const service = google.calendar({
version: 'v3',
auth: auth
});
For more info see service-account-credentials有关更多信息,请参阅service-account-credentials
Not found
未找到
Error normally means that you do not have access to the calendar you are trying to access.错误通常意味着您无权访问您尝试访问的日历。 I would check to be sure the delegation was setup properly to the calendar.
我会检查以确保代表团按照日历正确设置。 Try testing with a calendar.get to be sure you have access.
尝试使用 calendar.get 进行测试以确保您可以访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.