How to create a new google meet using google calendar api - reactjs

I need implement a javascript project that creates a new google meet according to the user signed in and adds the event to the calendar and gets the url of the google meet. How can i create a new google meet using Google Calendar API in JS.

Answer:
You need to use the conferenceData.createRequest parameter of the Events resource when creating a Calendar.Events: insert request to add a Meet link to a Calendar Event.
More Information:
As per the documention for 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.
With this information we can generate a Calendar Event creation request with a Meet link as the conference solution.
Example Request:
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"
}
});
NB: In order for a Meet link to be generated, you must set conferenceData.createRequest.requestId to any random string. For each new meet link you wish to create, you must use a different string in the request.
References:
Events: insert | Calendar API | Google Developers
Events | Calendar API | Google Developers

If you aren't using the node library, the request with axios is below. I did not realize from the answer above conferenceDataVersion is a query param.
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,
});

Extending #Brit's comment in googleapis npm package the way it should be executed will be
let response = await calendar.events.insert({
auth: auth,
calendarId: calendarId,
resource: event,
conferenceDataVersion: 1
});
with event as
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"
}
},
};

Related

Next-Auth | When user object have too many items then session request is without data

I will try to explain my problem as best as possible for me.
I'm using Strapi as a backend and Nextjs as a frontend.
For the authentication I using NextAuth.
[...nextauth].js:
const options = {
providers: [
Providers.Credentials({
name: 'Credentials',
credentials: {
username: { label: "Email", type: "email", placeholder: "jsmith" },
password: { label: "Password", type: "password" }
},
authorize: async (credentials) => {
try {
const user = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/auth/local`, {
identifier: credentials.username,
password: credentials.password,
});
if (user.data) {
return user.data
} else {
return null
}
} catch (error) {
const errorMessage = error.response.data.message[0].messages[0].message
throw new Error(errorMessage)
}
}
}),
],
database: process.env.NEXT_PUBLIC_DATABASE_URL,
session: {
jwt: true,
},
callbacks: {
jwt: async (token, user) => {
if (user) {
token.jwt = user.jwt;
token.user = user.user;
}
return Promise.resolve(token);
},
session: async (session, token) => {
session.jwt = token.jwt;
session.user = token.user;
return Promise.resolve(session);
},
},
pages: {
signIn: '/login',
error: '/login'
},
};
const Auth = (req, res) =>
NextAuth(req, res, options);
export default Auth;
When I send form with identifier and password I getting session response with user data and jwt.
Everything working well, but if user objects have few more objects assigned to him, then something goes wrong and the session is empty.
Example:
I creating in Strapi simple collection with just two fields - image field, and owner (relation to user). Every response with image contents few lines:
"photo": {
"_id": "60ca03fa20bd43033a53950e",
"name": "Zrzut ekranu 2021-06-16 o 14.59.48.png",
"alternativeText": "",
"caption": "",
"hash": "Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b",
"ext": ".png",
"mime": "image/png",
"size": 170.69,
"width": 668,
"height": 636,
"url": "/uploads/Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b.png",
"formats": {
"thumbnail": {
"name": "thumbnail_Zrzut ekranu 2021-06-16 o 14.59.48.png",
"hash": "thumbnail_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b",
"ext": ".png",
"mime": "image/png",
"width": 164,
"height": 156,
"size": 14.92,
"path": null,
"url": "/uploads/thumbnail_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b.png"
},
"small": {
"name": "small_Zrzut ekranu 2021-06-16 o 14.59.48.png",
"hash": "small_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b",
"ext": ".png",
"mime": "image/png",
"width": 500,
"height": 476,
"size": 121.79,
"path": null,
"url": "/uploads/small_Zrzut_ekranu_2021_06_16_o_14_59_48_2bc223567b.png"
}
},
When I add 1 or 2 items with image and try to login to user who own that items then everything is fine, I can log in and receive full user object and jwt token.
But when I add 3 items there, session object is empty, and I can't log in. I do not receiving user object and jwt token.
With 3 items
With 2 items
When I using postman, even with 50 items response is good and include full user object and jwt token.
I think is because response is too large or something like that, but I have no clue how to deal with it.
I working on localhost (both - frontend and backend) on MacOS.
Is there anyone who can help me find a solution for that problem?
Kind Regards,
GP
The reason of above issue is that in api response is passed to many data, and next-auth store that all data in JWT, and JWT is stored in full in cookie, cookie is limited to 4096 bytes, and that simply brake that limit and response.
The simplest way to sort it out is to save only most important data in JWT.
You can do that in callback function.

How can I create meeting with 3 persons using Google Calendar's API?

I am building a recruiting platform where an employer can book a meeting with a potential candidate. The owner of the website must be in this meeting.
So, basically, I would need to create a Google Meet with 3 invitations (us + 2 other people with email that are changing). Is there a way to achieve that using the Calendar API?
Thanks
When creating Calendar Events with Google Meet using Events.insert method, you need to do the following:
Set conferenceDataVersion parameter to 1
Version 1 enables support for copying of ConferenceData as well as for creating new conferences using the createRequest field of conferenceData.
To create new conference details, use createRequest field of conferenceData. Set conferenceSolutionKey type to "hangoutsMeet" and set a random string for requestId in the request body.
Sample conferenceData:
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"requestId": "7qxalsvy0exxaje"
}
}
If you want to send meeting invite to different people using Events.insert method, you need to do the following:
Set sendUpdates parameter to "all" to send notifications to all the guests invited.
Add event guests' using attendees properties in the request body.
Sample:
"attendees": [
{
"email": "user1#email.com"
},
{
"email": "user2#email.com"
}
],
Sample Events.insert parameters and request body:
{
"end": {
"dateTime": "2021-01-01T04:00:00+08:00"
},
"start": {
"dateTime": "2021-01-01T03:00:00+08:00"
},
"attendees": [
{
"email": "user1#email.com"
},
{
"email": "user2#email.com"
}
],
"conferenceData": {
"createRequest": {
"conferenceSolutionKey": {
"type": "hangoutsMeet"
},
"requestId": "7qxalsvy0exxaje"
}
},
"summary": "Sample Meeting"
}
Output:
References:
Create Events using Calendar API
Add video and phone conferences to events
Calendar API Reference

Create Event linked to Team Channel - Microsoft Api Graph

I'm trying to create an event into a calendar that mocks an event created directly on Microsoft Teams. So basically when you create an event via Microsoft Teams you can specify the group & the channel that must be part of the event.
I'm using the proper endpoint: https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http.
This is the info I'm passing as post request :
{
subject:"Event Subjct",
isOrganizer: true,
start: {
dateTime:"2020-12-29T12:00:00",
timeZone:"Pacific Standard Time"
},
end: {
dateTime:"2020-12-29T14:00:00",
timeZone:"Pacific Standard Time"
},
isAllDay: false,
allowNewTimeProposals: true,
isOnlineMeeting: true,
attendees: {
{
emailAddress: {
address:"<groupName#emailaddress.ext>", <-- got directly from Azure
name:"<TeamGroupName>"
},
type:"required"
}
},
hideAttendees: false,
type: "singleInstance",
transactionId: "<UNIQUE_ID>",
onlineMeetingProvider: "teamsForBusiness"
}
Note: all values between <..> are placeholder.
The event is correctly created but there's no reference on the Team channel group specified in the attendees field. I've search the definition of attendees array and there's nothing specific to note a group+channel in the attendee collection : https://learn.microsoft.com/en-us/graph/api/resources/attendee?view=graph-rest-1.0
Any help?
Thanks
You need to use the following API call to create the event in the Groups. For example, you need to use:
POST https://graph.microsoft.com/v1.0/groups/01d4ee64-15ce-491e-bad1-b91aa3223df4/events
Content-type: application/json
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does late morning work for you?"
},
"start": {
"dateTime": "2019-06-16T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-06-16T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Cafe"
},
"attendees": [
{
"emailAddress": {
"address":"adelev#contoso.onmicrosoft.com",
"name": "Adele Vance"
},
"type": "required"
}
]
}

dev_appserver.py locally rejects PATCH requests but accepts it on deployed

I've got an app based on djangoappengine, Backbone.js and Django REST Framework that uses PATCH requests to update models via {patch: true} on a model.save call.
I've found that when testing locally the dev_appserver returns:
ERROR 2014-02-19 04:37:04,531 dev_appserver.py:3081] code 501, message Unsupported method ('PATCH')
INFO 2014-02-19 04:37:04,532 dev_appserver.py:3090] "PATCH /api/posts/5707702298738688 HTTP/1.1" 501 -
Yet when I deploy it and access it through appspot the server happily accepts the request. Which forces me to deploy every time I make a change and want to test it.
I'm running the latests version (1.89) of the Python SDK, and found and old fixed issue that seems to tackle it but it seems other people have had it.
I tried this patch but it didn't make a difference. I don't understand why the development server would reject them and not the production server, is there something I need to change?
Thanks.
To update a resource, you can use POST with the x-http-method-override to patch. This is a valid RESTful operation and using POST will be more compatible with firewall and older user agents. The data in the request should indicate what is to be updated.
var url = '/api/posts/5707702298738688'
var patch_ops = [
{ "op": "replace", "path": "/properties/", "author": text}
{ "op": "add", "path": "/replies/", {"author": text, "comment":"blah"}}
/*
{ "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
*/
];
var xhr = jQuery.ajax({
type: "POST",
beforeSend: function (request)
{
request.setRequestHeader("X-HTTP-Method-Override", "PATCH");
},
url: url,
data: my_json_string,
dataType:"json",
success: function(data) {
return data;
},
error: function(xhr, textStatus, error){
return error;
}
});
Server handler:
def post(self, object_name):
if self.request.headers['x-http-method-override'] == 'PATCH':
# update according to patch operations
patch_ops_str= self.request.body.decode('utf-8')
try:
patch_ops = json.loads(new_area_geojson_str)
except:
self.response.set_status(400)
return self.response.out.write('{"status": "error", "reason": "JSON Parse error" }')
else:
self.response.set_status(405)
return self.response.out.write('{"status": "error", "reason": "post not accepted without x-http-method-override to PATCH" }')
Adapted from Please do not patch like an idiot

Backbone Model.fetch returns data but does not update model

I am running into an issue when my Model is fetched from the server. I see the correct JSON returned back from the server in chrome dev tools but the model does not update with the returned values.
var listtemplate = new ListTemplateModel.Model({id: id});
listtemplate.fetch();
I see the correct data in Chrome dev tools at this point. Here is what comes back from the server:
{
"title": "Template one",
"id": "template_one",
"steps": [
{
"description": "I love it",
"id": 1,
"created_at": "2012-12-24T18:01:48.402Z"
},
{
"description": "This is rubbish!",
"id": 1,
"created_at": "2012-12-24T18:01:48.402Z"
}
],
"created_at": "2012-12-24T18:01:48.402Z"
}
but console logging the JSON show me just the default value and the id that was passed in during the model creation.
console.log(listtemplate.toJSON());
and this returns:
{id: "template_one", title: "", steps: Array[0]}
My model looks like this (I am using Require.js, hence the Model has been renamed to ListTemplateModel above)
var Model = B.Model.extend({
defaults: {
title: '',
id: 0,
steps: []
},
urlRoot: 'xxx'
});
Any ideas?
Edit
#Amulya's answer set me on the right track and then i discovered "then". Hope this helps someone running into the same issue:
listtemplate.fetch().then(function(){
//update the view
});
The reason maybe because you do not wait for the fetch to be completed. Try this:
var listtemplate = new ListTemplateModel.Model({id: id});
listtemplate.fetch({
success: function() {
// fetch successfully completed
console.log(listtemplate.toJSON());
},
error: function() {
console.log('Failed to fetch!');
}
});

Resources