Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Traceback (most recent call last):
- File "email_clean.py", line 14, in <module>
- creds = store.get()
- File "C:Python27libsite-packagesoauth2clientclient.py", line 407, in get
- return self.locked_get()
- File "C:Python27libsite-packagesoauth2clientfile.py", line 54, in locked_get
- credentials = client.Credentials.new_from_json(content)
- File "C:Python27libsite-packagesoauth2clientclient.py", line 302, in new_from_json
- module_name = data['_module']
- KeyError: '_module'
- """
- Shows basic usage of the Gmail API.
- Lists the user's Gmail labels.
- """
- from __future__ import print_function
- from apiclient.discovery import build
- from httplib2 import Http
- from oauth2client import file, client, tools
- # Setup the Gmail API
- SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
- store = file.Storage('token.json')
- creds = store.get()
- if not creds or creds.invalid:
- flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
- creds = tools.run_flow(flow, store)
- service = build('gmail', 'v1', http=creds.authorize(Http()))
- # Call the Gmail API
- 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'])
Add Comment
Please, Sign In to add comment