質問編集履歴
2
不要な情報を削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -60,5 +60,4 @@
|
|
60
60
|
- docker コンテナを立ち上げ直したり
|
61
61
|
|
62
62
|
# 参考
|
63
|
-
- Python 3.6.5
|
64
63
|
- Google Calendar API v3
|
1
コードを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,52 @@
|
|
5
5
|
- コードを元に戻したが、アクセスできないまま
|
6
6
|
- docker コンテナを立ち上げ直したりしたが元に戻らず
|
7
7
|
|
8
|
+
# コード
|
9
|
+
```python
|
10
|
+
from flask import Flask, render_template
|
11
|
+
import datetime
|
12
|
+
import pickle
|
13
|
+
import os.path
|
14
|
+
from googleapiclient.discovery import build
|
15
|
+
from google_auth_oauthlib.flow import InstalledAppFlow
|
16
|
+
from google.auth.transport.requests import Request
|
17
|
+
|
18
|
+
SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
|
19
|
+
|
20
|
+
app = Flask(__name__)
|
21
|
+
|
22
|
+
|
23
|
+
@app.route('/', methods=['GET'])
|
24
|
+
def index():
|
25
|
+
creds = None
|
26
|
+
if os.path.exists('token.pickle'):
|
27
|
+
with open('token.pickle', 'rb') as token:
|
28
|
+
creds = pickle.load(token)
|
29
|
+
if not creds or not creds.valid:
|
30
|
+
if creds and creds.expired and creds.refresh_token:
|
31
|
+
creds.refresh(Request())
|
32
|
+
else:
|
33
|
+
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
|
34
|
+
creds = flow.run_local_server(port=0)
|
35
|
+
with open('token.pickle', 'wb') as token:
|
36
|
+
pickle.dump(creds, token)
|
37
|
+
|
38
|
+
service = build('calendar', 'v3', credentials=creds)
|
39
|
+
|
40
|
+
now = datetime.datetime.utcnow().isoformat() + 'Z'
|
41
|
+
events_result = service.events().list(calendarId='primary', timeMin=now,
|
42
|
+
maxResults=10, singleEvents=True,
|
43
|
+
orderBy='startTime').execute()
|
44
|
+
events = events_result.get('items', [])
|
45
|
+
|
46
|
+
return render_template('index.html', events=events)
|
47
|
+
|
48
|
+
|
49
|
+
if __name__ == "__main__":
|
50
|
+
app.run(host='0.0.0.0', port=5002, debug=True)
|
51
|
+
```
|
52
|
+
|
53
|
+
|
8
54
|
# エラー
|
9
55
|
- docker-compose logs でエラーを確認したところ
|
10
56
|
- ModuleNotFoundError: No module named 'googleapiclient'
|