我遵循了 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())
如果您的应用程序正在测试,刷新令牌将在 7 天后过期。
完成测试后,请转到 Google 控制台上针对您的项目的同意屏幕,然后单击按钮将其投入生产