Python 如何在firebase DB Auth令牌过期之前刷新它?

Python 如何在firebase DB Auth令牌过期之前刷新它?,python,firebase-realtime-database,firebase-authentication,access-token,Python,Firebase Realtime Database,Firebase Authentication,Access Token,我正在使用python编写firebase DB。我有数千个数据集,需要几个小时才能完成。我的程序多次因此错误而停止 “身份验证令牌已过期” 我搜索了解决方案,但没有找到任何解决方案,我后来发现,可以检查剩余的时间,然后刷新令牌,这样数据传输就不会有任何中断。 如何在令牌过期之前刷新令牌?您可以在令牌即将过期时使用google oauth2库刷新令牌,如下所示: import httplib2 from oauth2client.service_account import ServiceAcc

我正在使用python编写firebase DB。我有数千个数据集,需要几个小时才能完成。我的程序多次因此错误而停止

“身份验证令牌已过期”

我搜索了解决方案,但没有找到任何解决方案,我后来发现,可以检查剩余的时间,然后刷新令牌,这样数据传输就不会有任何中断。
如何在令牌过期之前刷新令牌?

您可以在令牌即将过期时使用google oauth2库刷新令牌,如下所示:

import httplib2
from oauth2client.service_account import ServiceAccountCredentials
credentials = ServiceAccountCredentials.from_json_keyfile_name("service-account.json", "{scope}")
print(credentials.get_access_token())
credentials.refresh(httplib2.Http())
print(credentials.get_access_token())

我将django与firebase和pyrebase模块一起使用。我也遇到了类似的问题。我在github上找到了解决方案:-> 紧接着这个代码->

config = {
    'apiKey': "your-api-key",
    'authDomain': "your-auth-domain",
    'databaseURL': "your-db-url",
    'projectId': "your-project-id",
    'storageBucket': "your-storage-bucket",
    'messagingSenderId': "your-messaging-sender-id",
}
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
user = auth.sign_in_with_email_and_password("email@sthn.com", "strong-password")
加上这个

# A user's idToken expires after 1 hour, so be sure to use the user's refreshToken to avoid stale tokens.
user = auth.refresh(user['refreshToken'])
# now we have a fresh token
user['idToken']