2017-09-12 16 views
0

xeroとc#windowsサービスアプリケーションを統合したいと考えています。 xeroとc#を接続するための簡単なコードスニペットが見つかりませんでした。 xeroを使ってユーザーを認証している間、私はユーザーとのやりとりを望んでいません。Xero Public Application Integration with C#

私は以下のコードを見つけましたが、認証するためにxeroログインページにリダイレクトしてから、検証コードを生成します。これを避けて、Windowsサービスでは検証コードを入力するGUIがないので、

using System; 
using System.Linq; 
using System.Windows.Forms; 
using Xero.Api.Core; 
using Xero.Api.Example.Applications.Public; 
using Xero.Api.Example.TokenStores; 
using Xero.Api.Infrastructure.OAuth; 
using Xero.Api.Serialization; 


namespace XeroIntegrationTest 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
      ConnectXero(); 
     } 

     public void ConnectXero() 
     { 
      try 
      { 
       // Public Application Sample 
       var user = new ApiUser { Name = Environment.MachineName }; 
       string consumerKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
       string consumerSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 

       var public_app_api = new XeroCoreApi("https://api.xero.com/api.xro/2.0/", new PublicAuthenticator("https://api.xero.com/api.xro/2.0/", "https://api.xero.com/oauth/RequestToken", "oob", 
        new MemoryTokenStore()), 
        new Consumer(consumerKey, consumerSecret), user, 
        new DefaultMapper(), new DefaultMapper()); 


       var public_contacts = public_app_api.Contacts.Find().ToList(); 

      } catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message + ex.StackTrace); 
      } 
     } 
    } 
} 

しかし oauth_problem = PERMISSION_DENIED & oauth_problem_advice =%20consumer%20was%20denied%20access%20to%20this%20resource

エラーを生成します。

誰かが私を助けてくれることを願っています。

答えて

0

"PrivateAuthenticator"メソッドを使用して統合する必要があります。使用しているメソッドはパブリックなもので、Windowsサービスには適していない別の認証プロセスを使用します。 "マイアプリ" セクション

  • 選択するようにXero developer portal
  • Goは
  • を "アプリケーションの追加" 訪問が(ラジオボタンのオプションからこれを "プライベート" を選択し

    1. :これを行うには

      重要です)

    2. 秘密/公開キーの組み合わせを生成する(Googleでこれを行う方法)
    3. 012のコードサンプルに従ってくださいPrivateAuthenticatorメソッドを使用して接続を設定する場合
  • 1

    「privateKeyAuthendicator」メソッドと統合する必要があります。

    https://developer.xero.com/documentation/api-guides/create-publicprivate-key

    2.Create ConsumerKeyとConsumerSecret

    プロジェクトフォルダに3.Includeキーファイルのリンクの下に使用して1.Create公開鍵/秘密鍵:これを行うには

    次のコードスニペットを使用してXeroにアクセスしてください

    var private_app_api = new XeroCoreApi(_xeroSettings.Value.Url, new PrivateAuthenticator(privatekeyFilePath, privatekeypassword), 
           new Consumer(consumerKey,consumerSecret), null, 
           new DefaultMapper(), new DefaultMapper());