コード例 #1
0
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            //App認証の場合
            if (SetTwitterApiKeys.UseAppOnlyAutherentcation || AppOnlyAuthentication != null)
            {
                if (AppOnlyAuthentication == null)
                {
                    AppOnlyAuthentication = new AppOnlyAuthentication();
                }
                AppOnlyAuthentication.SetUp(this);
                token = OAuth2.GetToken(AppOnlyAuthentication.ConsumerKey, AppOnlyAuthentication.ConsumerSecret);
            }
            else
            {
                //普通の認証の場合
                if (GetOAuthTokens() == null)
                {
                    var session = OAuth.Authorize(ConsumerKey, ConsumerSecret);
                    ReportManage.Report(this, "PINがありません。ブラウザに表示されているPINの値を入力してください。PIN=\"(表示されているPIN)\" とTwitterLoginクラスに情報を追加してください");
                    System.Diagnostics.Process.Start(session.AuthorizeUri.ToString());

                    Task reportProgressTask = Task.Factory.StartNew(() =>
                    {
                        PinDialog pin = new PinDialog();
                        if (pin.ShowDialog() == true)
                        {
                            var tokens = session.GetTokens(pin.PIN);


                            TokenData td = new TokenData()
                            {
                                ConsumerKey       = ConsumerKey,
                                ConsumerSecret    = ConsumerSecret,
                                AccessToken       = tokens.AccessToken,
                                AccessTokenSecret = tokens.AccessTokenSecret
                            };
                            this.Token     = new Tokens(tokens);
                            this.TokenData = td;
                            System.Xaml.XamlServices.Save(tokenSettingFileName, td);
                        }
                        else
                        {
                            return;
                        }
                    },
                                                                    CancellationToken.None,
                                                                    TaskCreationOptions.None,
                                                                    RawlerLib.UIData.UISyncContext);
                    reportProgressTask.Wait();
                }
            }
            base.Run(runChildren);
        }
コード例 #2
0
        public CoreTweet.Core.TokensBase GetOAuthTokens()
        {
            if (System.IO.File.Exists(tokenSettingFileName))
            {
                try
                {
                    var t = System.Xaml.XamlServices.Load(tokenSettingFileName);
                    if (t is TokenData)
                    {
                        var td = t as TokenData;

                        token = new Tokens()
                        {
                            AccessToken       = td.AccessToken,
                            AccessTokenSecret = td.AccessTokenSecret,
                            ConsumerKey       = td.ConsumerKey,
                            ConsumerSecret    = td.ConsumerSecret
                        };

                        this.TokenData = t as TokenData;
                    }
                    else
                    {
                        ReportManage.ErrReport(this, tokenSettingFileName + "の形式がおかしいみたいです。");
                        token = null;
                    }
                }
                catch (Exception e)
                {
                    ReportManage.ErrReport(this, tokenSettingFileName + "を開くのに失敗しました" + e.Message);
                    token = null;
                }
            }
            else
            {
                token = null;
            }
            return(token);
        }
コード例 #3
0
ファイル: TwitterLogin.cs プロジェクト: kiichi54321/Rawler
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            //App認証の場合
            if (SetTwitterApiKeys.UseAppOnlyAutherentcation || AppOnlyAuthentication != null)
            {
                if(AppOnlyAuthentication == null)
                {
                    AppOnlyAuthentication = new AppOnlyAuthentication();
                }
                AppOnlyAuthentication.SetUp(this);
                token = OAuth2.GetToken(AppOnlyAuthentication.ConsumerKey, AppOnlyAuthentication.ConsumerSecret);
            }
            else
            {
                //普通の認証の場合
                if (GetOAuthTokens() == null)
                {
                    var session = OAuth.Authorize(ConsumerKey, ConsumerSecret);
                    ReportManage.Report(this, "PINがありません。ブラウザに表示されているPINの値を入力してください。PIN=\"(表示されているPIN)\" とTwitterLoginクラスに情報を追加してください");
                    System.Diagnostics.Process.Start(session.AuthorizeUri.ToString());

                    Task reportProgressTask = Task.Factory.StartNew(() =>
                    {
                        PinDialog pin = new PinDialog();
                        if (pin.ShowDialog() == true)
                        {
                            var tokens = session.GetTokens(pin.PIN);

                            TokenData td = new TokenData()
                            {
                                ConsumerKey = ConsumerKey,
                                ConsumerSecret = ConsumerSecret,
                                AccessToken = tokens.AccessToken,
                                AccessTokenSecret = tokens.AccessTokenSecret
                            };
                            this.Token = new Tokens(tokens);
                            this.TokenData = td;
                            System.Xaml.XamlServices.Save(tokenSettingFileName, td);
                        }
                        else
                        {
                            return;
                        }

                    },
             CancellationToken.None,
             TaskCreationOptions.None,
             RawlerLib.UIData.UISyncContext);
                    reportProgressTask.Wait();

                }
            }
            base.Run(runChildren);
        }
コード例 #4
0
ファイル: TwitterLogin.cs プロジェクト: kiichi54321/Rawler
        public CoreTweet.Core.TokensBase GetOAuthTokens()
        {
            if (System.IO.File.Exists(tokenSettingFileName))
            {
                try
                {
                    var t = System.Xaml.XamlServices.Load(tokenSettingFileName);
                    if (t is TokenData)
                    {
                        var td = t as TokenData;

                        token = new Tokens()
                        {
                            AccessToken = td.AccessToken,
                            AccessTokenSecret = td.AccessTokenSecret,
                            ConsumerKey = td.ConsumerKey,
                            ConsumerSecret = td.ConsumerSecret
                        };

                        this.TokenData = t as TokenData;
                    }
                    else
                    {
                        ReportManage.ErrReport(this, tokenSettingFileName + "の形式がおかしいみたいです。");
                        token = null;
                    }
                }
                catch (Exception e)
                {
                    ReportManage.ErrReport(this, tokenSettingFileName + "を開くのに失敗しました" + e.Message);
                    token = null;
                }
            }
            else
            {
                token = null;
            }
            return token;
        }