2014-10-08 18 views
14

Genel uygulama için xero API'yı php ile bütünleştirmek istiyorum.xero API entegrasyonu

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

ben xml verilerini aşağıdaki geçirerek: Ben github https://github.com/XeroAPI/XeroOAuth-PHP den indirme koduna sahip oauth uygulama yetkisi şaşırıp Aşağıdaki kodu kullanıyorum
(kamu uygulama için xero api kod örneği bulunur)

$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];  
}  

Önce oauth belirteci benim ve oauth fatura url içine geçen

$response = $XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array('oauth_token'=>$oauth_token), $xml);  

Şimdi yanıt alıyorum 401 error yanıt, oauth jetonu eşleşmiyor

Ne yapıyorum?

+2

Bunun yerine bu kitaplığı kullanmanızı öneririm. Aslında aktif olarak korunur, iyi yapılandırılmış, hata ayıklaması kolaydır ve yazar aslında dinler: https://github.com/calcinai/xero-php xero tarafından sağlanan resmi php kütüphanesi ... * ısırık dili * ... iyi değil. – Gerry

cevap

1

Xero ile OAuth hataları alıyorsanız, bunların OAuth Issues article olası bir çözümü sağlamaya yardımcı olur. Bu, "belirteç uyuşmazlığı" ifadesinden bahsedilmiyor - Xero topluluğundaki hataya referans bulabilirdim.

Yayınladığınız öğelere dayanarak, ilk soru OAuth işlemini tamamladınız mı? Üç ana adım vardır (istek belirteci, kullanıcı yetkilendirmesi, erişim belirteci alın) ve yukarıdaki örneğiniz yalnızca ilk adımı gösterir. Başvuruda bulunduğunuz public.php dosya tüm adımları içerir.

OAuth işleminin sorunsuz bir şekilde çalışmasını istiyorsanız, OAuth erişim belirtecinin ve sırrının isteğinizle aktarıldığından emin olun (örnek isteğinizde yalnızca belirteç gösterilir). Sen XeroOAuth nesnesinde bu ayarlayabilirsiniz, bu yüzden OAuth'u ve fatura oluşturma ortaya koyduğunu XeroOauth-PHP public.php kapalı tabanlı komple süreci ile a gist yaptık

$XeroOAuth->config ['access_token'] = $oauth_token; 
$XeroOAuth->config ['access_token_secret'] = $oauth_token_secret; 
$XeroOAuth->request('POST', $XeroOAuth->url('Invoices', 'core'), array(), $xml); 

gibi son isteği görünebilir.