個人のGoogleアカウントでGmail APIを試してみました。簡単にするため、consider the Python QuickStart example(これは問題ありません)。問題は、同じ方法でGmailにアクセスできないことです。続きApps for WorkにGmailにアクセスするには個人アカウントからGmail APIを使用しますか?
<HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/myworkemail%40myworkdomain.com/labels?alt=json returned "Delegation denied for [email protected]">
:
私は単にコードの私の仕事用メールアドレスを使用して私の個人的な電子メールアドレスを交換した場合...
results = service.users().labels().list(userId='myworkemail%40myworkdomain.com').execute()
...私は、標準の代表団がエラーを拒否された取得します以前のStackExchangeの質問のヒントはほとんどありませんでした。私は、service account and an authorised API callを作成するための手順を試してみました。サービスアカウントのフォームは私の個人アカウントの開発者コンソールです...
credentials = ServiceAccountCredentials.from_json_keyfile_name('service_account.json', scopes=SCOPES)
delegated_credentials = credentials.create_delegated('myworkemail%40myworkdomain.com')
http_auth = delegated_credentials.authorize(httplib2.Http())
service = discovery.build('gmail', 'v1', http=http_auth)
results = service.users().labels().list(userId='myworkemail%40myworkdomain.com').execute()
...が、代わりに別のエラーが表示されます。注意すべき
File "qs.py", line 70, in main
results = service.users().labels().list(userId='myworkemail%40myworkdomain.com').execute()
File "/usr/local/lib/python2.7/site-packages/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/googleapiclient/http.py", line 755, in execute
method=str(self.method), body=self.body, headers=self.headers)
File "/usr/local/lib/python2.7/site-packages/googleapiclient/http.py", line 93, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 597, in new_request
self._refresh(request_orig)
File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 863, in _refresh
self._do_refresh_request(http_request)
File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 932, in _do_refresh_request
raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
oauth2client.client.HttpAccessTokenRefreshError: unauthorized_client: Unauthorized client or scope in request.
もう一つのポイント:the API explorer examplesを私の仕事のアカウントとGmailのAPIリファレンスページの作業罰金上、マイアカウント」に認可として表示'私が望むのは同じ動作です:の場合 Gmailアカウント(個人または職場)は、明示的な承認の後、同じコードでアクセスできます。
助けてくれてありがとう、ありがとうございます。私はすぐに私の質問に答えを投稿します。 –