快速在线书籍如何刷新令牌进行身份验证



这是我的代码:

from intuitlib.client import AuthClient  # intuit library
from quickbooks import QuickBooks  # python-quickbooks package
# auth credentials to connect to the QBO account
auth_client = AuthClient(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
environment=ENV,
redirect_uri=REDIRECT_URI,
)
# directoryPath = parameters.directoryPath
# creating the client object to access the QBO account - if not able to connect, make 3 tries dans then stop
tries = 3
for i in range(tries):
try:
client = QuickBooks(
auth_client=auth_client,
refresh_token=REFRESH_TOKEN,
company_id=COMPANY_ID,
)
# get the refresh token returned
refresh_token_new = client.auth_client.refresh_token
# if the refresh token has changed, update it in the csv
if REFRESH_TOKEN != refresh_token_new:
print('Updating the refresh token. ' + REFRESH_TOKEN + ' --> ' + refresh_token_new)
# fieldnames list required for DictWriter
fieldnames = ['client_id', 'client_secret', 'company_id', 'refresh_token', 'env']
tempfile = NamedTemporaryFile(mode='w', delete=False)
with open('../meta.csv') as csvfile, tempfile:
reader = csv.DictReader(csvfile)
writer = csv.DictWriter(tempfile, fieldnames=fieldnames)
writer.writeheader()
values = next(reader)
values['refresh_token'] = refresh_token_new
writer.writerow(values)
# saving the contents of temp file into the main file
shutil.move(tempfile.name, '../meta.csv')

如果我的refresh_token有效,它可以工作,但在更新它时,它似乎丢失了它...... 我的对象自然是刷新令牌,以便自动访问QBO。

我没有看到你从哪里得到REFRESH_TOKEN以及如何在调用之间保存它。也许它迷路是有原因的。

此外,QuickBooks 类不会自动刷新令牌。您需要在代码/应用中显式执行此操作。

最新更新