Google 身份验证 API 在几次后没有刷新

问题描述 投票:0回答:1

我遵循了 google API 身份验证步骤,它最初有效,但几天后遵循相同的步骤并重新下载“秘密”给了我上述错误,我认为此流程应该刷新 Google API 令牌,还是我遗漏了什么?

def main():
    global credentials
    credentials = None
    client_secrets_path = r"C:/Users/Owner/Desktop/Code/Code/credentials.json" 
    if os.path.exists("token.json"):
        credentials = Credentials.from_authorized_user_file("token.json", SCOPES)
    if not credentials or not credentials.valid:
        if credentials and credentials.expired and credentials.refresh_token:
            credentials.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(client_secrets_path, SCOPES)
            credentials = flow.run_local_server(port=0)
        with open("token.json", "w") as token:
            token.write(credentials.to_json())
python google-sheets google-sheets-api google-api-python-client
1个回答
0
投票

如果您的应用程序正在测试,刷新令牌将在 7 天后过期。

完成测试后,请转到 Google 控制台上针对您的项目的同意屏幕,然后单击按钮将其投入生产

© www.soinside.com 2019 - 2024. All rights reserved.