I can access to youtube analytics by following the v2 sample code at https://github.com/youtube/api-samples/blob/master/python/yt_analytics_v2.py.
And my previous code (youtube api v1) successfully integrated with oauth2client's Storage so each time when my python script is run, I do not need to go to browser, choosing the account for granting the permission.
But when migrating to youtube api v2 I do not find any docs providing a working solution for preventing asking me granting permission by sign-in from browser, including https://developers.google.com/api-client-library/python/auth/installed-app and google/ duck duck go search.
It seems because the v2 code executes run_console() so the app keeps asking me to sign-in with a specific account.
Previously my code exploits oauth2client's Storage, etc APIs (it was working without a problem).
flags = tools.argparser.parse_args(args=[])
flags.noauth_local_webserver = True
flow = flow_from_clientsecrets(...)
storage = Storage("%s.v1.json" % sys.argv[0])
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run_flow(flow, storage, flags)
...
youtube = build(...)
I tried borrowing the code (for my v2 python script) from How do I use google.auth instead of oauth2client in Python to get access to my Google Calendar with code snippet similar to
creds = get_saved_credentials()
if not creds:
creds = get_credentials_via_oauth()
youtube = get_service(creds)
But it still asks me to choose an account (even I've chosen in the previous round) each time when executing the python script.
How can I fix this (prevent the python script asking me to choose account to sign in from browser)?
Thanks