質問編集履歴
2
エラーコード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
raise HttpError(resp, content, uri=self.uri)
|
32
32
|
|
33
|
-
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/gmail/v1/users/me/labels/
|
33
|
+
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/gmail/v1/users/me/labels/171ec39c227594c5?alt=json returned "Not Found">
|
34
34
|
|
35
35
|
```
|
36
36
|
|
1
情報加筆
test
CHANGED
File without changes
|
test
CHANGED
@@ -113,3 +113,67 @@
|
|
113
113
|
|
114
114
|
|
115
115
|
```
|
116
|
+
|
117
|
+
gmail_authの中身は以下です.
|
118
|
+
|
119
|
+
```python
|
120
|
+
|
121
|
+
import httplib2, os
|
122
|
+
|
123
|
+
from apiclient import discovery
|
124
|
+
|
125
|
+
from oauth2client import client
|
126
|
+
|
127
|
+
from oauth2client import tools
|
128
|
+
|
129
|
+
from oauth2client.file import Storage
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
# Gmail権限のスコープを指定
|
134
|
+
|
135
|
+
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
|
136
|
+
|
137
|
+
# ダウンロードした権限ファイルのパス
|
138
|
+
|
139
|
+
CLIENT_SECRET_FILE = 'client_id.json'
|
140
|
+
|
141
|
+
# ユーザーごとの設定ファイルの保存パス
|
142
|
+
|
143
|
+
USER_SECRET_FILE = 'credentials-gmail.json'
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
# ユーザー認証データの取得
|
148
|
+
|
149
|
+
def gmail_user_auth():
|
150
|
+
|
151
|
+
# ユーザーの認証データの読み取り
|
152
|
+
|
153
|
+
store = Storage(USER_SECRET_FILE)
|
154
|
+
|
155
|
+
credentials = store.get()
|
156
|
+
|
157
|
+
# ユーザーが認証済みか?
|
158
|
+
|
159
|
+
if not credentials or credentials.invalid:
|
160
|
+
|
161
|
+
# 新規で認証する
|
162
|
+
|
163
|
+
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
|
164
|
+
|
165
|
+
flow.user_agent = 'Python Gmail API'
|
166
|
+
|
167
|
+
credentials = tools.run_flow(flow, store, None)
|
168
|
+
|
169
|
+
print('認証結果を保存しました:' + USER_SECRET_FILE)
|
170
|
+
|
171
|
+
return credentials
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
# 認証実行
|
176
|
+
|
177
|
+
gmail_user_auth()
|
178
|
+
|
179
|
+
```
|