CLIENT_SECRETS_FILE = 'your_file.json'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.readonly'
STORAGE = Storage('storage')
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()
credentials = STORAGE.get()
if credentials is None or credentials.invalid:
    parser = argparse.ArgumentParser(parents=[argparser])
flags = parser.parse_args()
credentials = run_flow(flow, STORAGE, flags, http=http)
http = credentials.authorize(http)
gmApi = build('gmail', 'v1', http=http)
How to get Google Analytics credentials without gflags - using run_flow() instead?