我正在尝试为Python实现Quickbooks API,根据事务生成发票,并将它们发送到我的Quickbooks帐户。我正在使用thispython库来访问API,该API目前在0.5.1版本中,可以在PyPI上使用。我无法将应用程序连接到Quickbooks Online。在
我在Quickbooks上创建了一个开发人员帐户,并且可以访问我的应用程序令牌、消费者密钥和消费者机密。图书馆github页面上的指南让我很困惑,因为在“将应用程序连接到Quickbooks Online”下,步骤1和步骤2似乎相互关联,但有点相互独立;这主要是因为客户端变量的重新初始化。在
我应该有多个名为client的Quickbook对象,但是在我的代码中重新初始化它吗?在
我的代码如下:
def create_invoice():
consumer_key = 'MY-CONSUMER-KEY'
consumer_secret = 'MY-CONSUMER-SECRET'
client = QuickBooks(
sandbox=True,
consumer_key=consumer_key,
consumer_secret=consumer_secret,
callback_url='https://sandbox-quickbooks.api.intuit.com',
)
authorize_url = client.get_authorize_url()
request_token = client.request_token
request_token_secret = client.request_token_secret
client = QuickBooks(
sandbox=True,
consumer_key=consumer_key,
consumer_secret=consumer_secret
)
client.authorize_url = authorize_url
client.request_token = request_token
client.request_token_secret = request_token_secret
client.set_up_service()
client.get_access_tokens(request.vars.oauth_verifier)
realm_id = request.vars.realmId
access_token = client.access_token
access_token_secret = client.access_token_secret
client = QuickBooks(
sandbox=True,
consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret,
company_id=realm_id
)
invoice = Invoice()
line = SalesItemLine()
line.LineNum = 1
line.Description = "description"
line.Amount = 100
line.SalesItemLineDetail = SalesItemLineDetail()
item = Item.all(max_results=1, qb=client)[0]
line.SalesItemLineDetail.ItemRef = item.to_ref()
invoice.Line.append(line)
customer = Customer.all(max_results=1, qb=client)[0]
invoice.CustomerRef = customer.to_ref()
invoice.CustomerMemo = CustomerMemo()
invoice.CustomerMemo.value = "Customer Memo"
invoice.save(qb=client)
有了这个代码,我得到了一个错误:
^{pr2}$因为我犯了错误,一定是出了问题,但我现在很困惑该怎么办。在
我找到了问题的答案。在阅读了这篇thread之后,我对库的工作有了更好的了解;主要是幕后的流程。我最终发现我提供的回调url是错误的。选择一个回调url,该url指向您在上面运行的代码。我还选择将我的大部分变量存储在数据库中,这样我就可以方便地访问它们以备将来使用。我的代码现在如下所示:
相关问题 更多 >
编程相关推荐