from oauth2client import tools
flags = tools.argparser.parse_args(args=[])
credentials = tools.run_flow(flow, storage, flags)
How to get Google Analytics credentials without gflags - using run_flow() instead?