Credentials.from_authorized_user_file refresh_token is missing

未關閉
#209 3 則留言 5 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
25/100
Issue 類型
文件
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
json, python

研究方向

The traceback points to quickstart.py calling Credentials.from_authorized_user_file('token.json', SCOPES), which raises from from_authorized_user_info in google/oauth2/credentials.py. The reporter's token.json is a downloaded OAuth client secrets file with an 'installed' key, not an authorized-user token, so start by checking how the quickstart tells users to create token.json. Done means the quickstart or its error path makes that mistake clear, which needs a maintainer decision on the intended fix.

由索引模型根據 Issue 內容生成。

描述

Expected Behavior

quickstart.py script will give me the last 10 login as described here:
https://developers.google.com/admin-sdk/reports/v1/quickstart/python

Actual Behavior

I'm trying to run the quickstart.py with a downloaded token.json for Desktop apps.

{
    "installed": {
        "client_id": "************.apps.googleusercontent.com",
        "project_id": "sentinel-314815",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "*************",
        "redirect_uris": [
            "urn:ietf:wg:oauth:2.0:oob",
            "http://localhost"
        ]
    }
}

It gives me the following erro:

$ python quickstart.py 
Traceback (most recent call last):
  File "quickstart.py", line 50, in <module>
    main()
  File "quickstart.py", line 20, in main
    creds = Credentials.from_authorized_user_file('token.json', SCOPES)
  File "/home/zfejer/.local/lib/python3.8/site-packages/google/oauth2/credentials.py", line 326, in from_authorized_user_file
    return cls.from_authorized_user_info(data, scopes)
  File "/home/zfejer/.local/lib/python3.8/site-packages/google/oauth2/credentials.py", line 277, in from_authorized_user_info
    raise ValueError(
ValueError: Authorized user info was not in the expected format, missing fields client_secret, client_id, refresh_token.

Seems like the refresh_token is missing from my token.json. I've just generated the token.json.

Steps to Reproduce the Problem

  1. follow the instruction on the page above

Specifications

  • Python version (python --version) Python 3.8.5
  • OS (Mac/Linux/Windows) Ubuntu 20.04 on WSL2 (5.4.72-microsoft-standard-WSL2)
主要語言
Python
星號
1.4k
分支
917
平均合併
3 分鐘
30 天內合併 PR
1

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

googleworkspace/python-samples 的其他 Issue

查看 googleworkspace/python-samples 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。