I am trying to use the Python Google API, and encounter an issue when using Google's quickstart example from https://developers.google.com/people/quickstart/python#configure_the_sample, as-is. When I run this example the first time, it opens up the Web browser, allows me to authenticate, and it works perfectly fine. But then, if I run the script again, instead of authenticating, it tries to use the token that was saved in token.json
and this fails with:
Traceback (most recent call last):
File "/home/thomas/test.py", line 58, in <module>
main()
File "/home/thomas/test.py", line 24, in main
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
File "/home/thomas/.local/lib/python3.10/site-packages/google/oauth2/credentials.py", line 440, in from_authorized_user_file
return cls.from_authorized_user_info(data, scopes)
File "/home/thomas/.local/lib/python3.10/site-packages/google/oauth2/credentials.py", line 390, in from_authorized_user_info
raise ValueError(
ValueError: Authorized user info was not in the expected format, missing fields refresh_token.
What am I missing?