Created
January 19, 2022 17:35
-
-
Save whisher/f0f8ebee3e97ff12a4b64bb6ac32e7b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "[email protected]"; | |
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