1

xero を c# Windows サービス アプリケーションと統合したいと考えています。xero を c# に接続するための簡単なコード スニペットが見つかりませんでした。xero を使用してユーザーを承認する際に、ユーザーとの対話は必要ありません。

以下のコードを見つけましたが、認証のために 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=The%20consumer%20was%20denied%20access%20to%20this%20resource を生成します

エラー。

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

4

2 に答える 2