python - Accessing Apps for Work Gmail via Gmail API from personal account? -
i've been experimenting gmail api on personal google account. simplicity, consider python quickstart example (which works fine). problem i'm unable access work gmail using same approach.
if replace personal email address work email address in code...
results = service.users().labels().list(userid='myworkemail%40myworkdomain.com').execute()
...i standard delegation denied error:
<httperror 403 when requesting https://www.googleapis.com/gmail/v1/users/myworkemail%40myworkdomain.com/labels?alt=json returned "delegation denied mypersonalemail@gmail.com">
following few hints previous stackexchange questions, i've tried working through instructions make service account , authorised api call, service account form personal account's developer console...
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()
...but different error instead:
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.
one other point note: the api explorer examples on gmail api reference page work fine work account, , show authorised in 'my account'. want same behaviour: any gmail account (personal or work) accessible same code, following explicit authorisation.
you'll receive http status code response of 403 once exceeded per user rate limit of 250 quota units per user per second project given in gmail api - usage limits.
it recommended in manage delegation settings client application has delay between creation of more 1 delegate or between retrieval of newly created delegate , states each user delegating gmail access allowed maximum 25 delegates. may check documentation more notes regarding gmail delegation.
Comments
Post a Comment