I\'m trying to use the Google Drive API (v3) with Python to obtain and upload files to my Google Drive account.
I used this guide to setup my authentication: https:
Nevermind, I figured it out. hpaulj had it right.
In the get_credentials() method, right before it called run_flow(), I simply had to add a line saying:
flags=tools.argparser.parse_args(args=[])
credentials=tools.run_flow(flow, store, flags)
And at the beginning when I read the command line with my inputs, I simply used parser_known_flags() as hpaulj suggested!
Thanks, shishy
I think there have been other questions about argparse
and the google api
, but I haven't used the latter.
Parsers are independent and can't be over written. But they all (as a default anyways) use sys.argv[1:]
. So if your code runs before the other one, you can edit sys.argv
to remove the extra strings. Using parse_known_args
is a handy way of separating your arguments from ones the other parser(s) should use.
Often the parser is invoked from a if __name__
block. That way imported modules don't do parsing, only ones used as scripts. But I don't if the google api makes this distinction.