Python:QuickBooks API 集成

问题描述 投票:0回答:2

下午好,

我今天大部分时间都在尝试将我的 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":[]}

任何帮助将不胜感激!

谢谢!

python quickbooks
2个回答
4
投票

一切看起来都不错,只是不确定你的价值是什么

company_id
。对于
company_id
中的
client
变量,将其值设置为您拥有的
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.getenv('CLIENT_SECRET'),
    access_token=os.getenv('ACCESS_TOKEN'),
    environment='sandbox',
    redirect_uri='https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl',
)

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

client.get_report(report_type='ProfitAndLoss')

0
投票
from intuitlib.client import AuthClient
from intuitlib.enums import Scopes
import csv
from quickbooks import QuickBooks

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')

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

client.get_report(report_type='ProfitAndLoss')

© www.soinside.com 2019 - 2024. All rights reserved.