我想在PHP中集成公共應用程序xero api。 我堅持的OAuth應用程序授權 我從GitHub https://github.com/XeroAPI/XeroOAuth-PHP下載代碼(找到公共應用Xero的API代碼示例)
我使用下面的代碼:xero api集成在php中用於公共類型應用程序
require('/../lib/XeroOAuth.php');
require('/../_config.php');
$useragent = "Xero-OAuth-PHP Public";
$signatures = array (
'consumer_key' => 'app_consumre_key',
'shared_secret' => 'app_secret_key',
'core_version' => '2.0'
);
$XeroOAuth = new XeroOAuth (array_merge (array (
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures));
include 'tests.php';
我傳遞以下XML數據:
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Martin Hudson</Name>
</Contact>
<Date>2013-05-13T00:00:00</Date>
<DueDate>2013-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56a Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.00</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>";
$params = array (
'oauth_callback' => OAUTH_CALLBACK
);
$response1 = $XeroOAuth->request ('GET', $XeroOAuth->url ('RequestToken', ''), $params );
if ($XeroOAuth->response ['code'] == 200)
{
$outhtoken = $XeroOAuth->response ['response'];
$oauth_exp = explode('&',$outhtoken);
$oauth_exp_token = explode('=',$oauth_exp[1]);
$oauth_token = $oauth_exp_token[1];
}
首先我的OAuth令牌,並傳遞到OAuth的發票網址
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array('oauth_token'=>$oauth_token), $xml);
現在我得到401 error
作爲迴應,oauth令牌不匹配
我在做什麼錯誤?
我建議使用這個庫來代替。它實際上是積極維護,結構良好,易於調試,作者實際上聽:https://github.com/calcinai/xero-php 由xero提供的官方php庫是... *咬舌頭* ...不好。 – Gerry 2015-07-13 04:17:37