python Google身份验证问题:授权用户信息不是预期的格式,缺少字段refresh_token

7nbnzgx9  于 2023-05-05  发布在  Python
关注(0)|答案(2)|浏览(210)

我正在尝试使用Python Google API,在使用Google的quickstart示例时遇到了一个问题,该示例来自https://developers.google.com/people/quickstart/python#configure_the_sample。当我第一次运行这个示例时,它打开了Web浏览器,允许我进行身份验证,并且运行得非常好。但是,如果我再次运行脚本,而不是进行身份验证,它会尝试使用保存在token.json中的令牌,并且失败:

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.

我错过了什么?

myzjeezk

myzjeezk1#

我发现我的问题:我在Google Cloud控制台中的OAuth密钥被配置为“Web应用程序”OAuth密钥,而它应该是“桌面应用程序”密钥。有了这个固定的,一切都工作得很好。

1sbrub3j

1sbrub3j2#

我设法用这个问题的答案解决了它。看这个Not receiving Google OAuth refresh token

相关问题