teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

読みやすいに編集。文言を適切に修正

2021/01/28 23:35

投稿

yuuta_s
yuuta_s

スコア0

title CHANGED
File without changes
body CHANGED
@@ -4,27 +4,8 @@
4
4
 
5
5
  LaravelでGoogleカレンダーと連携したシステムを構築しています。[laravel-google-calendar](https://github.com/spatie/laravel-google-calendar)というパッケージを使用し、Googleカレンダーを操作する機能を実装しています。Googleの認証には[サービスアカウント](https://cloud.google.com/iam/docs/service-accounts?hl=ja)を使用しています。[Postman](https://www.postman.com/)からLaravelにリクエストを投げて機能の検証をしています。
6
6
 
7
- - Googleカレンダーから予定を取得す機能は実装できた
7
+ ### 発生してい問題・エラーメッセージ
8
8
 
9
- ```php
10
- namespace App\Http\Controllers;
11
-
12
- use Spatie\GoogleCalendar\Event;
13
- use Illuminate\Support\Carbon;
14
-
15
- class CalendarController extends Controller
16
- {
17
- public function index()
18
- {
19
- $event = new Event;
20
- $events = Event::get();
21
- foreach ($events as $event) {
22
- echo $event->name . '';
23
- }
24
- }
25
- }
26
- ```
27
-
28
9
  - Googleカレンダーから予定を追加する機能は実装できた
29
10
 
30
11
  ```php
@@ -97,8 +78,15 @@
97
78
 
98
79
  [参考にした記事](https://reffect.co.jp/html/google-api%e3%82%92%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b%e3%81%9f%e3%82%81%e3%81%ae%e3%82%b5%e3%83%bc%e3%83%93%e3%82%b9%e3%82%a2%e3%82%ab%e3%82%a6%e3%83%b3%e3%83%88%e3%81%ae%e8%a8%ad%e5%ae%9a%e8%aa%8d)
99
80
 
100
- ### 実装手順2(サービスアカウントのドメイン全体の委任有効にする
81
+ ### 実装手順2(サービスアカウントのドメイン全体の権限の委任有効
101
82
 
83
+ #### サービスアカウントにドメイン全体の委任を有効
84
+
85
+ 1. 作成したサービスアカウントに画面遷移
86
+ 2. 編集ボタンを押下
87
+ 3. 「G Suite ドメイン全体の委任を有効にする」チェックボタンを押下
88
+ 4. 保存
89
+
102
90
  #### サービスアカウントにカレンダースコープを提供
103
91
 
104
92
  1. [Google Admin](https://admin.google.com/)にログイン
@@ -144,7 +132,7 @@
144
132
  /*
145
133
  * The id of the Google Calendar that will be used by default.
146
134
  */
147
- 'calendar_id' => env('GOOGLE_CALENDAR_ID1'),
135
+ 'calendar_id' => env('GOOGLE_CALENDAR_ID'),
148
136
  ];
149
137
  ```
150
138
 
@@ -194,7 +182,7 @@
194
182
 
195
183
  - .envの設定
196
184
  ```
197
- GOOGLE_CALENDAR_ID1=test1@gmail.com
185
+ GOOGLE_CALENDAR_ID=test1@gmail.com
198
186
  ```
199
187
 
200
188
  ### 補足情報(FW/ツールのバージョンなど)

5

画像の差し替え

2021/01/28 23:35

投稿

yuuta_s
yuuta_s

スコア0

title CHANGED
File without changes
body CHANGED
@@ -113,7 +113,7 @@
113
113
  1. Google Cloud PlatformのIAMの画面にログイン
114
114
  2. サービスアカウントで作成したメールをIAMにオーナー権限で追加
115
115
 
116
- ![イメージ説明](1ea8bd0dbd9d942d6b70a2f39ad23713.png)
116
+ ![イメージ説明](02c29487295f6c15561f12cc413218bb.png)
117
117
 
118
118
  ### 実装手順3(Googleカレンダーの設定)
119
119
 

4

タイトル変更

2021/01/28 10:28

投稿

yuuta_s
yuuta_s

スコア0

title CHANGED
@@ -1,1 +1,1 @@
1
- LaravelでGoogleカレンダーの予定作成する際に「ゲストを追加」したい
1
+ LaravelでGoogleカレンダーの予定作成に「ゲストを追加」したい(Google Calendar API Service Account Error)
body CHANGED
File without changes

3

情報を追加

2021/01/28 10:22

投稿

yuuta_s
yuuta_s

スコア0

title CHANGED
File without changes
body CHANGED
@@ -125,15 +125,15 @@
125
125
  4. 権限は「予定の変更」
126
126
  5. カレンダーIDの取得
127
127
 
128
+ ![イメージ説明](cdc8fd1eb8b0e6a01bdd3082b9d4a3cb.png)
129
+
128
130
  ### 実装手順4(Laravel)
129
131
 
130
132
  - Composerでlaravel-google-calendar "2.2.2"をインストール
131
133
  - サービスプロバイダーの設定
132
- - configの設定
134
+ - config/google-calendar.phpの設定
133
135
 
134
- ```config/google-calendar.php
135
- <?php
136
+ ```php
136
-
137
137
  return [
138
138
 
139
139
  /*
@@ -151,7 +151,7 @@
151
151
  - app/google-calendar配下にサービスアカウントでダウンロードしたファイルをservice-account-credentials.json名で保存
152
152
  - ルーティングの設定
153
153
 
154
- ```routes/api.php
154
+ ```php
155
155
  Route::resource(
156
156
  'calendar',
157
157
  'CalendarController',
@@ -160,14 +160,13 @@
160
160
  ```
161
161
 
162
162
  - コントローラの設定
163
- ```app/Http/Controllers/CalendarController.php
163
+ ```php
164
164
  namespace App\Http\Controllers;
165
165
 
166
166
  use Illuminate\Http\Request;
167
167
  use Spatie\GoogleCalendar\Event;
168
168
  use Illuminate\Support\Carbon;
169
169
 
170
-
171
170
  class CalendarController extends Controller
172
171
  {
173
172
  public function index()
@@ -194,8 +193,7 @@
194
193
  ```
195
194
 
196
195
  - .envの設定
197
- ```.env
196
+ ```
198
- GOOGLE_CALENDAR_ID=XXXXXXXXX@group.calendar.google.com
199
197
  GOOGLE_CALENDAR_ID1=test1@gmail.com
200
198
  ```
201
199
 
@@ -206,5 +204,6 @@
206
204
  spatie/laravel-google-calendar 2.2.2
207
205
 
208
206
  ### 参考にした記事
209
- https://stackoverflow.com/questions/60760959/google-calendar-api-service-account-error
207
+ [https://stackoverflow.com/questions/60760959/google-calendar-api-service-account-error](https://issuetracker.google.com/issues/141704931)
210
- https://issuetracker.google.com/issues/141704931
208
+ [https://issuetracker.google.com/issues/141704931](https://issuetracker.google.com/issues/141704931)
209
+ [https://github.com/spatie/laravel-google-calendar/issues/125](https://github.com/spatie/laravel-google-calendar/issues/125)

2

情報を追加

2021/01/28 10:21

投稿

yuuta_s
yuuta_s

スコア0

title CHANGED
File without changes
body CHANGED
@@ -58,7 +58,7 @@
58
58
  $event->name = '検証用';
59
59
  $event->startDateTime = Carbon::now();
60
60
  $event->endDateTime = Carbon::now()->addHour();
61
- $event->addAttendee(['email' => 'test1@gmail.com']); // この一行を追加
61
+ $event->addAttendee(['email' => 'test2@gmail.com']); // この一行を追加
62
62
  $event->description = "テスト説明文\nテスト説明文\nテスト説明文";
63
63
  $event->save();
64
64
 
@@ -115,7 +115,7 @@
115
115
 
116
116
  ![イメージ説明](1ea8bd0dbd9d942d6b70a2f39ad23713.png)
117
117
 
118
- ### Googleカレンダーの設定
118
+ ### 実装手順3(Googleカレンダーの設定
119
119
 
120
120
  アカウントA(test1@gmail.com)とアカウントB(test2@gmail.com)の設定
121
121
 
@@ -125,13 +125,86 @@
125
125
  4. 権限は「予定の変更」
126
126
  5. カレンダーIDの取得
127
127
 
128
+ ### 実装手順4(Laravel)
128
129
 
130
+ - Composerでlaravel-google-calendar "2.2.2"をインストール
131
+ - サービスプロバイダーの設定
132
+ - configの設定
129
133
 
134
+ ```config/google-calendar.php
135
+ <?php
130
136
 
137
+ return [
131
138
 
139
+ /*
140
+ * Path to the json file containing the credentials.
141
+ */
142
+ 'service_account_credentials_json' => storage_path('app/google-calendar/service-account-credentials.json'),
132
143
 
144
+ /*
145
+ * The id of the Google Calendar that will be used by default.
146
+ */
147
+ 'calendar_id' => env('GOOGLE_CALENDAR_ID1'),
148
+ ];
149
+ ```
150
+
151
+ - app/google-calendar配下にサービスアカウントでダウンロードしたファイルをservice-account-credentials.json名で保存
152
+ - ルーティングの設定
153
+
154
+ ```routes/api.php
155
+ Route::resource(
156
+ 'calendar',
157
+ 'CalendarController',
158
+ ['only' => ['index', 'store']]
159
+ );
160
+ ```
161
+
162
+ - コントローラの設定
163
+ ```app/Http/Controllers/CalendarController.php
164
+ namespace App\Http\Controllers;
165
+
166
+ use Illuminate\Http\Request;
167
+ use Spatie\GoogleCalendar\Event;
168
+ use Illuminate\Support\Carbon;
169
+
170
+
171
+ class CalendarController extends Controller
172
+ {
173
+ public function index()
174
+ {
175
+ $event = new Event;
176
+ $events = Event::get();
177
+ foreach ($events as $event) {
178
+ echo $event->name . '';
179
+ }
180
+ }
181
+
182
+ public function store()
183
+ {
184
+ $event = new Event;
185
+ $event->name = '検証用';
186
+ $event->startDateTime = Carbon::now();
187
+ $event->endDateTime = Carbon::now()->addHour();
188
+ $event->addAttendee(['email' => 'test2@gmail.com']);
189
+ $event->description = "テスト説明文\nテスト説明文\nテスト説明文";
190
+ $event->save();
191
+
192
+ return '成功';
193
+ }
194
+ ```
195
+
196
+ - .envの設定
197
+ ```.env
198
+ GOOGLE_CALENDAR_ID=XXXXXXXXX@group.calendar.google.com
199
+ GOOGLE_CALENDAR_ID1=test1@gmail.com
200
+ ```
201
+
133
202
  ### 補足情報(FW/ツールのバージョンなど)
134
203
 
135
204
  Laravel 5.8.36
136
205
  PHP 7.3
137
- spatie/laravel-google-calendar 2.2.2
206
+ spatie/laravel-google-calendar 2.2.2
207
+
208
+ ### 参考にした記事
209
+ https://stackoverflow.com/questions/60760959/google-calendar-api-service-account-error
210
+ https://issuetracker.google.com/issues/141704931

1

記入漏れ

2021/01/28 10:07

投稿

yuuta_s
yuuta_s

スコア0

title CHANGED
File without changes
body CHANGED
@@ -108,17 +108,30 @@
108
108
 
109
109
  ![イメージ説明](a16bba29abc510c6062f3e974ab40cc0.png)
110
110
 
111
- #### 役割
111
+ #### IAMの設定
112
112
 
113
113
  1. Google Cloud PlatformのIAMの画面にログイン
114
114
  2. サービスアカウントで作成したメールをIAMにオーナー権限で追加
115
115
 
116
116
  ![イメージ説明](1ea8bd0dbd9d942d6b70a2f39ad23713.png)
117
117
 
118
+ ### Googleカレンダーの設定
118
119
 
120
+ アカウントA(test1@gmail.com)とアカウントB(test2@gmail.com)の設定
119
121
 
122
+ 1. カレンダーの追加
123
+ 2. カレンダーのアクセス設定
124
+ 3. 特定のユーザーとの共有設定でサービスアカウントで発行されたメールをを設定
125
+ 4. 権限は「予定の変更」
126
+ 5. カレンダーIDの取得
127
+
128
+
129
+
130
+
131
+
132
+
120
133
  ### 補足情報(FW/ツールのバージョンなど)
121
134
 
122
- ここにより詳細な情報を記載してください。
135
+ Laravel 5.8.36
123
-
124
- ### 参考にした記事
136
+ PHP 7.3
137
+ spatie/laravel-google-calendar 2.2.2