Google Calendar API를 사용하여 공휴일을 받는 PHP
흐름으로는
느낌이 듭니다.
Google Developers Console

google에 로그인한 상태에서 Google Developers Console에 액세스하세요.
이 화면의 '프로젝트 만들기'에서 프로젝트 이름을 넣고 '만들기' 버튼을 누릅니다.

작성이 완료되면 다음과 같은 화면으로 전환합니다.

이것으로 프로젝션 생성이 완료됩니다.
API 사용
생성 직후의 화면에서 'Google API 사용'이라는 링크가 있습니다.

이 링크로 전환하면 '활성화 할 수있는 API 목록'이 표시됩니다.

이번에는 Calendar API를 다루므로 검색 상자에 Calendar API를 입력하고 결과 링크에서 개요 페이지로 전환합니다.

개요
개요 페이지는 이런 느낌

여기에서 API를 활성화하고 API 키를 가져옵니다. 먼저 여기에서 "API 활성화"버튼을 눌러 활성화합시다.
몇 초가 지나면 다음과 같이 "이 API가 활성화되어 있지만 자격 증명을 만들 때까지 프로젝트에서 사용할 수 없습니다."라는 메시지가 표시되므로 자격 증명을 만듭니다.

즉시 "인증 정보로 이동"을 클릭하여 자격 증명을 등록합시다.
전환 대상 화면은 이런 식으로

이 화면 상단의 "이 절차를 건너 뛰고 ..."에서 "API 키"를 클릭하면 "어떤 유형의 키"를 만들 것인지 묻기 때문에 이번에는 "서버 키"를 만듭니다.


그러면 다음 화면에서 "서버 키 이름"과 "허용할 IP 주소"를 지정하는 화면이 열립니다.

여기에 '서버 키 이름'과 '허용할 IP 주소'를 입력하고 '만들기' 버튼을 눌러 완료합니다.

API는 목록 화면에서도 확인할 수 있습니다.

이것으로 API 키 검색이 완료됩니다.
공휴일을 얻는 코드
여러가지 부족합니다만, api_key 의 취급에는 주의해 주세요.
<?php
$api_key = 'さっき取得したAPIキーをこちらに';
$holidays_id = '[email protected]';
$holidays_url = sprintf(
'https://www.googleapis.com/calendar/v3/calendars/%s/events?'.
'key=%s&timeMin=%s&timeMax=%s&maxResults=%d&orderBy=startTime&singleEvents=true',
$holidays_id,
$api_key,
$start_date,
$end_date,
30
);
if( $results = file_get_contents($holidays_url, true))
{
$results = json_decode($results);
$holidays = array();
foreach($results->items as $item)
{
$date = strtotime((string) $item->start->date);
$title = (string) $item->summary;
$holidays[date('Y-m-d', $date)] = $title;
}
ksort($holidays);
}
?>
주의점
생성 직후의 화면에서 'Google API 사용'이라는 링크가 있습니다.

이 링크로 전환하면 '활성화 할 수있는 API 목록'이 표시됩니다.

이번에는 Calendar API를 다루므로 검색 상자에 Calendar API를 입력하고 결과 링크에서 개요 페이지로 전환합니다.

개요
개요 페이지는 이런 느낌

여기에서 API를 활성화하고 API 키를 가져옵니다. 먼저 여기에서 "API 활성화"버튼을 눌러 활성화합시다.
몇 초가 지나면 다음과 같이 "이 API가 활성화되어 있지만 자격 증명을 만들 때까지 프로젝트에서 사용할 수 없습니다."라는 메시지가 표시되므로 자격 증명을 만듭니다.

즉시 "인증 정보로 이동"을 클릭하여 자격 증명을 등록합시다.
전환 대상 화면은 이런 식으로

이 화면 상단의 "이 절차를 건너 뛰고 ..."에서 "API 키"를 클릭하면 "어떤 유형의 키"를 만들 것인지 묻기 때문에 이번에는 "서버 키"를 만듭니다.


그러면 다음 화면에서 "서버 키 이름"과 "허용할 IP 주소"를 지정하는 화면이 열립니다.

여기에 '서버 키 이름'과 '허용할 IP 주소'를 입력하고 '만들기' 버튼을 눌러 완료합니다.

API는 목록 화면에서도 확인할 수 있습니다.

이것으로 API 키 검색이 완료됩니다.
공휴일을 얻는 코드
여러가지 부족합니다만, api_key 의 취급에는 주의해 주세요.
<?php
$api_key = 'さっき取得したAPIキーをこちらに';
$holidays_id = '[email protected]';
$holidays_url = sprintf(
'https://www.googleapis.com/calendar/v3/calendars/%s/events?'.
'key=%s&timeMin=%s&timeMax=%s&maxResults=%d&orderBy=startTime&singleEvents=true',
$holidays_id,
$api_key,
$start_date,
$end_date,
30
);
if( $results = file_get_contents($holidays_url, true))
{
$results = json_decode($results);
$holidays = array();
foreach($results->items as $item)
{
$date = strtotime((string) $item->start->date);
$title = (string) $item->summary;
$holidays[date('Y-m-d', $date)] = $title;
}
ksort($holidays);
}
?>
주의점
<?php
$api_key = 'さっき取得したAPIキーをこちらに';
$holidays_id = '[email protected]';
$holidays_url = sprintf(
'https://www.googleapis.com/calendar/v3/calendars/%s/events?'.
'key=%s&timeMin=%s&timeMax=%s&maxResults=%d&orderBy=startTime&singleEvents=true',
$holidays_id,
$api_key,
$start_date,
$end_date,
30
);
if( $results = file_get_contents($holidays_url, true))
{
$results = json_decode($results);
$holidays = array();
foreach($results->items as $item)
{
$date = strtotime((string) $item->start->date);
$title = (string) $item->summary;
$holidays[date('Y-m-d', $date)] = $title;
}
ksort($holidays);
}
?>
Reference
이 문제에 관하여(Google Calendar API를 사용하여 공휴일을 받는 PHP), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Chrowa3/items/93c55d83b972d0ddfa10텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)