1๏ธโฃ ๋ชฉํ
- FullCalendar์์ ๋ ์ง๋ฅผ ํด๋ฆญ โ ๋ชจ๋ฌ์ฐฝ ์
๋ ฅ โ ์ ์ถ โ ๐ Google Calendar์ ์ผ์ ์๋ ๋ฑ๋ก
2๏ธโฃ GCP ์ค๋น: OAuth 2.0 ์ค์
- ํ๋ก์ ํธ ์์ฑ
- API ๋ฐ ์๋น์ค โ ๋ผ์ด๋ธ๋ฌ๋ฆฌ โ "Google Calendar API" ํ์ฑํ
- ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด > OAuth 2.0 ํด๋ผ์ด์ธํธ ID ์์ฑ
client_secret.json
๋ค์ด๋ก๋
src/main/resources/
ํด๋์ ์ ์ฅ
.gitignore
์ ๋ฑ๋กํด์ผ ํจ
3๏ธโฃ HTML ๊ตฌ์ฑ (FullCalendar + Bootstrap ๋ชจ๋ฌ)
โ
์บ๋ฆฐ๋ ๋ ๋๋ง + ํด๋ฆญ ์ ๋ชจ๋ฌ ๋์ฐ๊ธฐ
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendar = new FullCalendar.Calendar(document.getElementById('calendar'), {
initialView: 'dayGridMonth',
googleCalendarApiKey: '๋ฐ๊ธ๋ฐ์ API ํค',
events: {
googleCalendarId: '๋ด ๊ตฌ๊ธ ์บ๋ฆฐ๋ ID'
},
dateClick: function(info) {
const form = document.dateForm;
form.date.value = info.dateStr;
document.querySelector('.date-event-modal').click();
}
});
calendar.render();
});
</script>
<form name="dateForm" action="/google/cal/post">
<input name="date">
<input name="title">
<textarea name="desc"></textarea>
<button>์ผ์ ์ถ๊ฐ</button>
</form>
4๏ธโฃ ๋ฐฑ์๋: ์ผ์ ๋ฑ๋ก ์ปจํธ๋กค๋ฌ
@GetMapping("/google/cal/post")
public RedirectView post(@RequestParam String title, @RequestParam String desc, @RequestParam String date) {
return new RedirectView("/google/cal");
}
5๏ธโฃ GoogleCalendar ํด๋์ค ๊ตฌํ
โ
์ผ์ ๋ฑ๋ก + ์ธ์ฆ ์ฒ๋ฆฌ
public static Event addEvent(Event event) {
Calendar service = new Calendar.Builder(...).build();
return service.events().insert(CALENDAR_ID, event).execute();
}
private static Credential getCredentials(...) {
InputStream in = GoogleCalendar.class.getResourceAsStream("/client_secret.json");
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(...)
.setAccessType("offline").build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
6๏ธโฃ ์ต์ด ์คํ ์ ์ธ์ฆ ํ์ (์ฝ์ ์๋ด)
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth...
- URL์ ๋ธ๋ผ์ฐ์ ์ ๋ถ์ฌ๋ฃ๊ณ Google ๊ณ์ ๋ก๊ทธ์ธ
- ์ธ์ฆ ํ
localhost:8888/google/cal/callback
์ผ๋ก ์๋ ๋ฆฌ๋๋ ์
credentials/StoredCredential
์ ์ธ์ฆ ์ ๋ณด ์ ์ฅ๋จ
7๏ธโฃ ํ
์คํธ ํ๋ฆ
- ์๋ฒ ์คํ
- ๋ธ๋ผ์ฐ์ ์์
/google/cal
์ ์
- ๋ ์ง ํด๋ฆญ โ ๋ชจ๋ฌ์์ ์ ๋ชฉ/๋ด์ฉ ์์ฑ โ ์ผ์ ์ถ๊ฐ
- Google Calendar์์ ์ผ์ ๋ฑ๋ก ํ์ธ
๐ ๋ณด์ ์ฃผ์
client_secret.json
์ ๋ ์ธ๋ถ ๊ณต๊ฐ ๊ธ์ง!
.gitignore
์ ๋ฐ๋์ ์ถ๊ฐ:
src/main/resources/client_secret.json
credentials/
โ
๋์ค์ ๋ค์ ํ ๋๋ ๊ธฐ์ตํ ๊ฒ!
ํด์ผ ํ ๊ฒ | ์ด์ |
---|
OAuth ํด๋ผ์ด์ธํธ ID ๋ฑ๋ก | ์ธ์ฆ URL ๋ฆฌ๋๋ ์
๊ฒฝ๋ก ํ์ (/callback ) |
client_secret.json ์์น | resources/ ์ ๋๊ณ .gitignore ๋ฑ๋ก |
์ต์ด ์ธ์ฆ | ์ฝ์์์ URL ์ด๊ณ ํ ๋ฒ ๋ก๊ทธ์ธํด์ผ ํ ํฐ ์ ์ฅ๋จ |
FullCalendar์ ๋ฐฑ์๋ ์บ๋ฆฐ๋ ID ์ผ์น | ํ๋ก ํธ์ ๋ฐฑ์๋๊ฐ ๊ฐ์ ์บ๋ฆฐ๋ ์กฐ์ํด์ผ ํจ |