我想在 php 中为公共应用程序集成 xero api。我坚持使用 oauth 应用程序授权我从 github https://github.com/XeroAPI/XeroOAuth-PHP下载代码(在公共应用程序的 xero api 代码示例上查找)
我正在使用以下代码:
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 invoice url
$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array('oauth_token'=>$oauth_token), $xml);
现在我得到 401error
作为响应,oauth 令牌不匹配
我在做什么错误?