Created
January 19, 2020 12:54
-
-
Save arimichi/bacd46cb96d9e758164592b078bbf59d 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
// ******************************************** | |
// mtssb-booking-from.php変更 | |
// ******************************************** | |
// 679行から 追加 Googleカレンダー自動追加 | |
// composerでインストールしたライブラリを読み込む | |
require_once __DIR__.'/../../../../../../vendor/autoload.php'; | |
// サービスアカウント作成時にダウンロードしたjsonファイル | |
$aimJsonPath = __DIR__ . '/../../../../../../key/Project calendar-xxxxxxxxxxxxxxxx.json'; | |
// サービスオブジェクトを作成 | |
$client = new Google_Client(); | |
// このアプリケーション名 | |
$client->setApplicationName('カレンダー操作テスト イベントの取得'); | |
// ※ 注意ポイント: 権限の指定 | |
// 予定を取得する時は Google_Service_Calendar::CALENDAR_READONLY | |
// 予定を追加する時は Google_Service_Calendar::CALENDAR_EVENTS | |
$client->setScopes(Google_Service_Calendar::CALENDAR_EVENTS); | |
// ユーザーアカウントのjsonを指定 | |
$client->setAuthConfig($aimJsonPath); | |
// サービスオブジェクトの用意 | |
$service = new Google_Service_Calendar($client); | |
/* | |
* 予定の追加 | |
*/ | |
// 開始時刻 | |
$start_time = $booking['booking_time']; | |
$booking_date_time = date_i18n('c', $start_time); | |
// 終了時刻 3時間後 | |
$booking_end_time = date_i18n('c', $start_time+(60*60*3)); | |
// 名前 | |
$booking_summary = 'Web予約-' . esc_html($booking['client']['name']); | |
// カレンダーID | |
$calendarId = '〇〇●●●〇〇@gmail.com'; | |
$event = new Google_Service_Calendar_Event(array( | |
'summary' => $booking_summary, //予定のタイトル | |
'start' => array( | |
'dateTime' => $booking_date_time,// 開始日時 | |
'timeZone' => 'Asia/Tokyo', | |
), | |
'end' => array( | |
'dateTime' => $booking_end_time, // 終了日時 | |
'timeZone' => 'Asia/Tokyo', | |
), | |
)); | |
$event = $service->events->insert($calendarId, $event); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment