Created
October 11, 2024 09:10
-
-
Save bvlion/6f2497e6c3404542b23e2f635dccbf53 to your computer and use it in GitHub Desktop.
Google Calendar API で日本の公式祝日カレンダーを取得・表示する PHP サンプル
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
<?php | |
$year = "2024"; | |
$country_code = 'japanese'; | |
$api_key = 'your API KEY'; | |
$holidays_url = sprintf( | |
'https://www.googleapis.com/calendar/v3/calendars/%s/events?'. | |
'key=%s&timeMin=%s&timeMax=%s&orderBy=startTime&singleEvents=true', | |
'ja.' . $country_code . '.official%23holiday@group.v.calendar.google.com', | |
$api_key, | |
$year . '-01-01T00%3A00%3A00.000Z', | |
$year . '-12-31T00%3A00%3A00.000Z' | |
); | |
if ($results = file_get_contents($holidays_url, true)) { | |
$result_data = json_decode($results); | |
$holidays = []; | |
foreach ($result_data->items as $item) { | |
$holidays[date('Y-m-d', strtotime($item->start->date))] = $item->summary; | |
} | |
ksort($holidays); | |
} | |
var_dump(json_encode($holidays, true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment