Python:QuickBooksAPI集成

2024-09-30 01:35:03 发布

您现在位置:Python中文网/ 问答频道 /正文

下午好

我今天大部分时间都在努力出口宝洁公司;从我的QBO沙盒公司下载到python数据框架(或者至少是字典)中。我一直在遵循指令here,但我一辈子都无法让身份验证生效。 我一直在使用OAuth playground生成我的授权令牌,代码如下:

from intuitlib.client import AuthClient
from intuitlib.enums import Scopes
import csv

reader = csv.DictReader(open("/home/mike/home_health/quickbooks_details.csv"))
credentials = next(reader) 

auth_client = AuthClient(
    client_id=credentials.get('client_id'),
    client_secret=credentials.get('secret'),
    redirect_uri='https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl',
    environment='sandbox')

auth_client.get_bearer_token(auth_code='MY_AUTH_CODE', realm_id='MY_REALM_ID')


from quickbooks import QuickBooks

client = QuickBooks(
    auth_client=auth_client,
    refresh_token=auth_client.refresh_token,
    company_id=credentials.get('company_id'),
)

client.get_report(report_type='ProfitAndLoss')

尽管我可能会尝试,但仍会出现以下错误:

AuthorizationException: QB Auth Exception: Application authentication failed 

{"warnings":null,"intuitObject":null,"fault":{"error":[{"message":"message=DispatcherError; errorCode=003100; statusCode=401","detail":"","code":"3100","element":null}],"type":"AUTHENTICATION"},"report":null,"queryResponse":null,"batchItemResponse":[],"attachableResponse":[],"syncErrorResponse":null,"requestId":null,"time":1617720333515,"status":null,"cdcresponse":[]}

任何帮助都将不胜感激

谢谢


Tags: csvfromimportreportclienttokenauthid
1条回答
网友
1楼 · 发布于 2024-09-30 01:35:03

一切似乎都是对的,只是我不确定你对company_id有什么价值。对于client中的company_id变量,将其值设置为您拥有的Realm Id,然后尝试运行它。这对我有用

from intuitlib.client import AuthClient
from quickbooks import QuickBooks
import os

auth_client = AuthClient(
    client_id=os.getenv('CLIENT_ID'),
    client_secret=os.getnev('CLIENT_SECRET'),
    access_token=os.getnev('ACCESS_TOKEN'),
    environment='sandbox',
    redirect_uri='https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl',
)

client = QuickBooks(
    auth_client=auth_client,
    refresh_token=os.getnev('REFRESH_TOKEN'),
    company_id=os.getenv('REALM_ID'),
)

client.get_report(report_type='ProfitAndLoss')

相关问题 更多 >

    热门问题