python - quicks 在线书籍如何刷新令牌以进行身份验证。用蟒蛇
问题描述
这是我的代码:
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 类不会自动刷新令牌。您需要在代码/应用程序中明确执行此操作。
推荐阅读
- java - Java 框架/模式来修改值
- java - Kafka Streams - 应用程序 JVM 随机崩溃
- java - Java 泛型类绑定到类型扩展 T
- common-lisp - 运行尝试输出 Javascript 代码的通用 lisp 宏时键入错误。为什么?
- javascript - 需要设置超时需要在 if else 条件中进行以下更改
- gradle - Gradle build - 从下载的档案中解决依赖关系
- firebase - RN Firebase:未触发通知方法;消息方法是
- sql - SQL Server 如果存在重复则忽略行,除非 id 存在
- xml - 如何让每个办公室使用 XSLT 在单独的页面上打印?
- javascript - 我可以在 loopbackjs API 中禁用“包含”过滤器功能吗?