Skip to content

Instantly share code, notes, and snippets.

@whisher
Created January 19, 2022 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whisher/f0f8ebee3e97ff12a4b64bb6ac32e7b6 to your computer and use it in GitHub Desktop.
Save whisher/f0f8ebee3e97ff12a4b64bb6ac32e7b6 to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import { GoogleLoginProvider, SocialAuthService, SocialUser } from 'angularx-social-login';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'calendar-app';
user: SocialUser | undefined;
loggedIn = true;
calendarId = "davidederosa17@gmail.com";
token: string | undefined;
constructor(private authService: SocialAuthService) {
}
ngOnInit(): void {
this.authService.authState.subscribe((user) => {
this.user = user;
this.loggedIn = (user != null)
this.loggedIn = false
this.token = user.authToken;
sendEventToCalendar(this.token)
console.log(user);
})
}
onGoogleLoginClicked() {
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID);
}
signOut() {
this.authService.signOut();
}
sendEventToCalendar(token:string) {
const headers = new Headers({
"Content-type": "application/json",
'Authorization': 'Bearer' + token,
"Accept": "application / json"
})
const body = {
end: {
"dateTime": "2022-09-18T06:00:00+02:00",
"timeZone": "Europe/Zurich"
},
"start": {
"timeZone": "Europe/Zurich",
"dateTime": "2022-09-18T06:00:00+02:00"
}
}
const config = {
method: "POST",
body: JSON.stringify(body),
headers: headers,
}
fetch(`https://www.googleapis.com/calendar/v3/calendars/${this.calendarId}/events`, config)
.then(data => console.log(data))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment