quickbooks 在线如何刷新令牌以进行身份验证。 python
quicks books online how to refresh token to authenticate. with python
这是我的代码:
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 class 不会自动刷新令牌。您需要在 code/app.
中明确地这样做
这是我的代码:
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 class 不会自动刷新令牌。您需要在 code/app.
中明确地这样做