如何从 google.oauth2.service_account.Credentials 对象刷新凭据?

How to refresh credentials from google.oauth2.service_account.Credentials object?

我有一个 google.oauth2.service_account.Credentials 的实例。我应该如何刷新这些凭据。我得到 creds.expired 为真。

在阅读文档时 here,我得到了答案。我们可以使用以下方法刷新凭据并获取令牌:

import google.auth.transport.requests
import requests

request = google.auth.transport.requests.Request()

credentials.refresh(request)