如何使用 google 日历 api 创建新的 google 会议
How to create a new google meet using google calendar api
我需要实施一个 javascript 项目,根据登录的用户创建一个新的 google 会议并将事件添加到日历并获得 url google 见面。我如何在 JS 中使用 Google 日历 API 创建一个新的 google 会议。
答案:
创建 Calendar.Events 时需要使用事件资源的 conferenceData.createRequest
参数:插入请求以将 Meet link 添加到日历事件。
更多信息:
根据 Events: insert and the Event resource reperesentation 的文档:
conferenceDataVersion
: integer
Version number of conference data supported by the API client. Version 0 assumes no conference data support and ignores conference data in the event's body. Version 1 enables support for copying of ConferenceData as well as for creating new conferences using the createRequest field of conferenceData. The default is 0. Acceptable values are 0
to 1
, inclusive.
conferenceData.createRequest
: nested object
A request to generate a new conference and attach it to the event. The data is generated asynchronously. To see whether the data is present check the status
field.
Either conferenceSolution
and at least one entryPoint
, or createRequest
is required.
conferenceData.createRequest.conferenceSolutionKey.type
: string
The conference solution type.
If a client encounters an unfamiliar or empty type, it should still be able to display the entry points. However, it should disallow modifications.
The possible values are:
- "
eventHangout
" for Hangouts for consumers (http://hangouts.google.com)
- "
eventNamedHangout
" for classic Hangouts for G Suite users (http://hangouts.google.com)
- "
hangoutsMeet
" for Google Meet (http://meet.google.com)
- "
addOn
" for 3P conference providers
conferenceData.createRequest.requestId
: string
The client-generated unique ID for this request.
Clients should regenerate this ID for every new request. If an ID provided is the same as for the previous request, the request is ignored.
利用这些信息,我们可以生成一个日历事件创建请求,并以会议 link 作为会议解决方案。
示例请求:
gapi.client.calendar.events.insert({
"calendarId": "primary",
"conferenceDataVersion": 1,
"resource": {
"end": {
"date": "2020-10-24"
},
"start": {
"date": "2020-10-23"
},
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"requestId": "some-random-string"
}
},
"summary": "titles are cool"
}
});
注意: 为了生成 Meet link,您必须 将 conferenceData.createRequest.requestId
设置为 任意随机字符串 。对于您希望创建的每个新会议 link,您必须在请求中使用 不同的字符串。
参考文献:
如果您不使用节点库,请在下面使用 axios
的请求。我没有从上面的答案中意识到 conferenceDataVersion
是一个查询参数。
let event = {
summary: "some text",
location: "some text",
description: "some text",
start: {
dateTime: start,
timeZone: timeZone,
},
end: {
dateTime: end,
timeZone: timeZone,
},
recurrence: [],
attendees: [
{ email: 'johndoe@whatever.com' },
],
reminders: {
useDefault: true,
},
conferenceData: {
createRequest: {
conferenceSolutionKey: {
type: 'hangoutsMeet',
},
requestId: 'somerequestid',
},
},
};
const createEventRequest = await axios({
url: `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events?conferenceDataVersion=1`,
method: 'POST',
headers: {
Authorization: `Bearer ${accessToken}`,
},
data: event,
});
在 googleapis npm 包中扩展@Brit 的评论,其执行方式将是
let response = await calendar.events.insert({
auth: auth,
calendarId: calendarId,
resource: event,
conferenceDataVersion: 1
});
和event
一样
let event = {
'summary': `Appointment.`,
'description': `Description`,
'start': {
'dateTime': dateTime['start'],
'timeZone': 'Asia/Kolkata'
},
'end': {
'dateTime': dateTime['end'],
'timeZone': 'Asia/Kolkata'
},
'attendees': [
{'email': '...@gmail.com'},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"requestId": "JksKJJSK1KJSK"
}
},
};
我需要实施一个 javascript 项目,根据登录的用户创建一个新的 google 会议并将事件添加到日历并获得 url google 见面。我如何在 JS 中使用 Google 日历 API 创建一个新的 google 会议。
答案:
创建 Calendar.Events 时需要使用事件资源的 conferenceData.createRequest
参数:插入请求以将 Meet link 添加到日历事件。
更多信息:
根据 Events: insert and the Event resource reperesentation 的文档:
conferenceDataVersion
:integer
Version number of conference data supported by the API client. Version 0 assumes no conference data support and ignores conference data in the event's body. Version 1 enables support for copying of ConferenceData as well as for creating new conferences using the createRequest field of conferenceData. The default is 0. Acceptable values are
0
to1
, inclusive.
conferenceData.createRequest
:nested object
A request to generate a new conference and attach it to the event. The data is generated asynchronously. To see whether the data is present check the
status
field.Either
conferenceSolution
and at least oneentryPoint
, orcreateRequest
is required.
conferenceData.createRequest.conferenceSolutionKey.type
:string
The conference solution type.
If a client encounters an unfamiliar or empty type, it should still be able to display the entry points. However, it should disallow modifications.
The possible values are:
- "
eventHangout
" for Hangouts for consumers (http://hangouts.google.com)- "
eventNamedHangout
" for classic Hangouts for G Suite users (http://hangouts.google.com)- "
hangoutsMeet
" for Google Meet (http://meet.google.com)- "
addOn
" for 3P conference providers
conferenceData.createRequest.requestId
:string
The client-generated unique ID for this request. Clients should regenerate this ID for every new request. If an ID provided is the same as for the previous request, the request is ignored.
利用这些信息,我们可以生成一个日历事件创建请求,并以会议 link 作为会议解决方案。
示例请求:
gapi.client.calendar.events.insert({
"calendarId": "primary",
"conferenceDataVersion": 1,
"resource": {
"end": {
"date": "2020-10-24"
},
"start": {
"date": "2020-10-23"
},
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"requestId": "some-random-string"
}
},
"summary": "titles are cool"
}
});
注意: 为了生成 Meet link,您必须 将 conferenceData.createRequest.requestId
设置为 任意随机字符串 。对于您希望创建的每个新会议 link,您必须在请求中使用 不同的字符串。
参考文献:
如果您不使用节点库,请在下面使用 axios
的请求。我没有从上面的答案中意识到 conferenceDataVersion
是一个查询参数。
let event = {
summary: "some text",
location: "some text",
description: "some text",
start: {
dateTime: start,
timeZone: timeZone,
},
end: {
dateTime: end,
timeZone: timeZone,
},
recurrence: [],
attendees: [
{ email: 'johndoe@whatever.com' },
],
reminders: {
useDefault: true,
},
conferenceData: {
createRequest: {
conferenceSolutionKey: {
type: 'hangoutsMeet',
},
requestId: 'somerequestid',
},
},
};
const createEventRequest = await axios({
url: `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events?conferenceDataVersion=1`,
method: 'POST',
headers: {
Authorization: `Bearer ${accessToken}`,
},
data: event,
});
在 googleapis npm 包中扩展@Brit 的评论,其执行方式将是
let response = await calendar.events.insert({
auth: auth,
calendarId: calendarId,
resource: event,
conferenceDataVersion: 1
});
和event
一样
let event = {
'summary': `Appointment.`,
'description': `Description`,
'start': {
'dateTime': dateTime['start'],
'timeZone': 'Asia/Kolkata'
},
'end': {
'dateTime': dateTime['end'],
'timeZone': 'Asia/Kolkata'
},
'attendees': [
{'email': '...@gmail.com'},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"requestId": "JksKJJSK1KJSK"
}
},
};