Gmail API v1

I have setup the gmail api as per the instructions from the official site. Now when I am trying to call the API, I am getting a refresh error. This is code that I have used :

 

def get_gmail_service():
    credentials = Credentials.from_authorized_user_file(credentials_file, ['https://www.googleapis.com/auth/gmail.readonly'])
    service = build('gmail', 'v1', credentials=credentials)
    return service
 
def print_gmail_labels():
    service = get_gmail_service()
    results = service.users().labels().list(userId='me').execute()
    labels = results.get('labels', [])

    if not labels:
        print('No labels found.')
    else:
        print('Labels:')
        for label in labels:
            print(label['name'])
 
 
While calling the print_gmail_function() I am getting this error : 

RefreshError: ('unauthorized_client: Unauthorized', {'error': 'unauthorized_client', 'error_description': 'Unauthorized'})

In the above code, the credentails_file is the path to the required credentials in a json format.

1 0 176
0 REPLIES 0