1

I keep getting the above error and I am not sure how to solve this. I have enabled Domain wide Delegation and also authorized the Client-Id in 'Manage API Access'

My Code looks like this:

"""
Sample program    
"""

import googleapiclient.discovery
import json
import googleapiclient.errors 
from google.oauth2 import service_account 

SERVICE_ACCOUNT_FILE = 'abcd.json' 

credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE)

scoped_credentials = 
credentials.with_scopes(['https://mail.google.com/'])
delegated_credentials = credentials.with_subject('abcd')

service = googleapiclient.discovery.build('gmail','v1',credentials = delegated_credentials) 

try:
    results = service.users().labels().list(userId='abcd').execute()
except Exception as err:
    print err

Has anyone got this working ? If so please point out why I am getting the error.

  • Got it working. It was a silly mistake :) . – Shilpa Yellapragada May 11 '18 at 06:07
  • Changed delegated_credentials = credentials.with_subject('abcd') ----> delegated_credentials = scoped_credentials.with_subject('abcd') – Shilpa Yellapragada May 11 '18 at 06:07
  • After solving this problem, I wonder if you would mind telling me what I'm doing wrong? The second effort in https://stackoverflow.com/questions/52206251/authenticating-gmail-api-access-programmatically seems to do pretty much what yours does, but puts the scopes into the credential creation. – holdenweb Sep 08 '18 at 11:24

0 Answers0