Skip to content

Instantly share code, notes, and snippets.

@arimichi
Last active January 19, 2020 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arimichi/dcbe3bca71f7e97f12dd7d91849467ed to your computer and use it in GitHub Desktop.
Save arimichi/dcbe3bca71f7e97f12dd7d91849467ed to your computer and use it in GitHub Desktop.
<?php
/*
* 共通の記述
*/
// composerでインストールしたライブラリを読み込む
require_once __DIR__.'/../../../../../../vendor/autoload.php';
// fptでアップロードした場合は、
// require_once __DIR__.'/../../../../../../google-api-php-client/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);
/*
* 予定の追加
*/
// カレンダーID
$calendarId = '〇〇●●●〇〇@gmail.com';
$event = new Google_Service_Calendar_Event(array(
'summary' => 予約テスト, //予定のタイトル
'start' => array(
'dateTime' => 2019-02-01T10:00:00+09:00,// 開始日時
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => 2019-02-01T12:00:00+09:00, // 終了日時
'timeZone' => 'Asia/Tokyo',
),
));
$event = $service->events->insert($calendarId, $event);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>予定サンプル</title>
</head>
<body>
<h1>予定の追加</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment