Thomas Petazzoni
Thomas Petazzoni

Reputation: 5956

Google authentication issue: Authorized user info was not in the expected format, missing fields refresh_token

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?

Upvotes: 2

Views: 1955

Answers (2)

Realizt30
Realizt30

Reputation: 183

I managed to resolve it using the answer on this question. Check this out Not receiving Google OAuth refresh token

Upvotes: 0

Thomas Petazzoni
Thomas Petazzoni

Reputation: 5956

I found my issue: my OAuth key in the Google Cloud console was configured as a "web application" OAuth key, while it should have been a "desktop application" key. With that fixed, it all works perfectly well.

Upvotes: 3

Related Questions