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
エラーを生成します。
誰かが私を助けてくれることを願っています。