1

我们正在尝试使用 Ruby 1.9.3 (not RoR)与 QuickBooks Online V2 api 集成。使用API ExplorerEmployee 端点文档,我们能够通过使用Google Signet OAuth Gem获得一个简单的测试员工列表。

require 'signet'
require 'signet/oauth_1/client'

#intialize oauth1 client
@client = Signet::OAuth1::Client.new(
    :temporary_credential_uri => "https://oauth.intuit.com/oauth/v1/get_request_token",
    :authorization_uri => "https://appcenter.intuit.com/Connect/Begin",
    :token_credential_uri => "https://oauth.intuit.com/oauth/v1/get_access_token",
    :client_credential_key => 'qyprdPEfJqU7eOze0Fby9iYhrUS5DQ',
    :client_credential_secret => 'fuXsasJo4TrTEd3Yhv4TeMUizmtguh0JioIB5r2I',
    :callback => "http://localhost:3000/callback/general"
)

@client.token_credential_key = 'qyprdJUtDSk7owxVfZlq7JeWO1mtpHBkSMD5GhB02PwIC6N0'
@client.token_credential_secret = 'Rq2ekgQWWL9frZAKpcgWef291mR0J5HBE354u5F3'

#setup request
original_request = [
    'POST',
    'https://qbo.sbfinance.intuit.com/resource/employees/v2/791630875',
    # we also tried this url 'https://qbo.intuit.com/qbo28/resource/employees/v2/791630875',
    [
        ['Content-Type', 'application/x-www-form-urlencoded'],
    ],
    []
]
#execute request
response = @client.fetch_protected_resource(:request => original_request)
puts response.body

如您所见,请求非常简单。但是,一旦我们在正文中创建了一个带有过滤器的请求,我们就会得到一个带有以下错误的 HTML 页面:HTTP Status 401 - message=Exception authenticating OAuth; errorCode=003200; statusCode=401

#setup request
original_request = [
    'POST',
    'https://qbo.intuit.com/qbo28/resource/employees/v2/791630875',
    #'https://qbo.sbfinance.intuit.com/resource/employees/v2/791630875',
    [
        ['Content-Type', 'application/x-www-form-urlencoded'],
    ],
    ["Filter=Name :EQUALS: Doe"]
]

我们正在使用 Google OAuth gem,并且我已经使用以下工具验证了签名生成是正确的:LinkedIn Oauth Test ConsoleBeginners guide to OAuth signing requests。他们都验证 Signet 生成的签名对于我提供的正文是否正确。

我查看了一些 SO Questions:

但没有任何效果。任何帮助将不胜感激,我们愿意使用第三方 gem,例如quickeebooks,但我们不愿意。我想我只是在这里遗漏了一些简单的东西。

请向我提供以下项目,以便我验证有效的答案:

  • 您的请求参数,包括 uri、标头、正文和确切的客户端和访问令牌(仅限开发人员应用令牌,我需要验证我是否可以生成完全相同的请求,包括签名)
  • 您用于生成 HMAC-SHA1 签名的 basestring。它看起来像

POST&https%3A%2F%2Fqbo.intuit.com%2Fqbo28%2Fresource%2Femployees%2Fv2%2F7916308‌​75&Filter%3DName%2520%253AEQUALS%253A%2520David%2520Test%26oauth_consumer_key%3Dq‌​yprdPEfJqU7eOze0Fby9iYhrUS5DQ%26oauth_nonce%3D-1787433535548338293%26oauth_signat‌​ure_method%3DHMAC-SHA1%26oauth_timestamp%3D1380089100%26oauth_token%3DqyprdJUtDSk‌​7owxVfZlq7JeWO1mtpHBkSMD5GhB02PwIC6N0%26oauth_version%3D1.0

  • 您的回复,包括标题和正文数据
4

2 回答 2

0

我曾尝试将过滤查询与员工端点一起使用。它工作正常。

编辑- 共享与员工 API 端点相关的端点、过滤器和结果集

https://qbo.intuit.com/qbo28/resource/employees/v2/791926875

Filter= Name :EQUALS: Manas Mukherjee

标题 -"Authorization: OAuth oauth_token="2eRrd7LhEtHrM1CrqWvy1kmSgeukEgFxW99E1xwhSsLCp1JB", oauth_consumer_key="qyprdXsaKh0a132eNs7NTJLufjfrzm", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1380084612", oauth_nonce="1556081845430558974", oauth_signature="IMjh%2FTx%2F7GMFDE6WQqZK8b6apjI%3D"[\r][\n]"

Content-Type: application/x-www-form-urlencoded

数据集

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<qbo:SearchResults xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
    <qbo:CdmCollections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Employees">
        <Employee>
            <Id idDomain="QBO">20</Id>
            <SyncToken>0</SyncToken>
            <MetaData>
                <CreateTime>2013-09-24T21:37:22-07:00</CreateTime>
                <LastUpdatedTime>2013-09-24T21:37:22-07:00</LastUpdatedTime>
            </MetaData>
            <Name>Manas Mukherjee</Name>
            <Address>
                <Line1>ABC Str</Line1>
                <City>London</City>
                <PostalCode>4353543</PostalCode>
                <GeoCode>LAT=51.5148382,LNG=-0.1264144</GeoCode>
            </Address>
            <GivenName>Manas</GivenName>
            <MiddleName>Kr</MiddleName>
            <FamilyName>Mukherjee</FamilyName>
            <ShowAs>Manas Kr Mukherjee</ShowAs>
            <BillableTime>false</BillableTime>
        </Employee>
    </qbo:CdmCollections>
    <qbo:Count>1</qbo:Count>
    <qbo:CurrentPage>1</qbo:CurrentPage>
</qbo:SearchResults>

使用您的令牌的OAuth 标头

"Authorization: OAuth oauth_token="qyprdJUtDSk7owxVfZlq7JeWO1mtpHBkSMD5GhB02PwIC6N0", oauth_consumer_key="qyprdPEfJqU7eOze0Fby9iYhrUS5DQ", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1380089100", oauth_nonce="-1787433535548338293", oauth_signature="Vj67xMVhSKGjVSmGyOxt7SVv0i8%3D"[\r][\n]"

端点 -https://qbo.intuit.com/qbo28/resource/employees/v2/791630875

将数据发布到端点:Filter= Name :EQUALS: David Test

内容类型:application/x-www-form-urlencoded

它工作正常谢谢

于 2013-09-25T04:29:20.907 回答
0

请参阅这个带有过滤器的示例提琴手请求以获取 QBO 中的项目。我无法在此处粘贴提琴手日志。您可以对 Employee 进行类似的操作。过滤器应该进入正文并编码您的标题:

请求-POST https://qbo.intuit.com/qbo1/resource/items/v2/723488155

HTTP/1.1 Content-Type: application/x-www-form-urlencoded Authorization: OAuth oauth_token="lvprdgF9q4mSQx5A6lKNm3NISXvwIpF16z",oauth_nonce="3740352e-20a4-4d45-af4f-2b783ee20e60",oauth_consumer_key="qyprd7I5WvVnPoiBh1ejZn",oauth_signature_method="HMAC- SHA1",oauth_timestamp="1377106651",oauth_version="1.0",oauth_signature="1OAJXk5uH0sEpYpdhh%2BDMzjQFEs%3D" 主机:qbo.intuit.com 内容长度:28 预期:100-继续

PageNum=1&ResultsPerPage=100

响应标头 - HTTP/1.1 200 OK 日期:2013 年 8 月 21 日星期三 17:37:31 GMT 服务器:Apache Set-Cookie:qboeuid=10.129.32.5.1377106651774076;路径=/; 到期=格林威治标准时间 14 年 8 月 21 日星期四 17:37:31;域=.intuit.com 设置 Cookie:JSESSIONID=82DE11473B5246497B9FDCD8A6DA4C45.c1-pprdqboas30j;路径=/; 安全的; HttpOnly 变化:接受编码内容类型:应用程序/xml;charset=UTF-8 内容长度:32525

于 2013-09-25T05:55:41.953 回答