コード例 #1
0
ファイル: TwitterApi.cs プロジェクト: moodmaker/BlockThemAll
        public void Authenticate(string verifier)
        {
            TwitterOAuth.TokenPair tokens = OAuth.AccessToken(verifier);

            if (tokens == null)
            {
                OAuth  = null;
                Status = UserStatus.NO_CREDITIONAL;
                return;
            }

            setting.SetValue(section, "AccessToken", OAuth.User.Token   = tokens.Token);
            setting.SetValue(section, "AccessSecret", OAuth.User.Secret = tokens.Secret);
            setting.Save();

            MyUserInfo = getMyUserInfo();
            Status     = MyUserInfo == null ? UserStatus.INVALID_CREDITIONAL : UserStatus.LOGIN_SUCCESS;
        }
コード例 #2
0
ファイル: TwitterApi.cs プロジェクト: moodmaker/BlockThemAll
        public static TwitterApi Login(IniSettings setting, string section)
        {
            TwitterApi api = new TwitterApi
            {
                setting = setting,
                section = section
            };

            string consumerKey    = Convert.ToString(setting.GetValue(section, "ConsumerKey", string.Empty));
            string consumerSecret = Convert.ToString(setting.GetValue(section, "ConsumerSecret", string.Empty));
            string accessToken    = Convert.ToString(setting.GetValue(section, "AccessToken", string.Empty));
            string accessSecret   = Convert.ToString(setting.GetValue(section, "AccessSecret", string.Empty));

            if (string.IsNullOrWhiteSpace(consumerKey) || string.IsNullOrWhiteSpace(consumerSecret))
            {
                setting.Save();
                api.Status = UserStatus.NO_APIKEY;
                return(api);
            }

            if (string.IsNullOrWhiteSpace(accessToken) || string.IsNullOrWhiteSpace(accessSecret))
            {
                api.OAuth = new TwitterOAuth(consumerKey, consumerSecret);
                TwitterOAuth.TokenPair tokens = api.OAuth.RequestToken();
                if (tokens == null)
                {
                    api.Status = UserStatus.NO_APIKEY;
                    return(api);
                }

                api.OAuth.User.Token  = tokens.Token;
                api.OAuth.User.Secret = tokens.Secret;
                api.Status            = UserStatus.LOGIN_REQUESTED;
                return(api);
            }

            api.OAuth      = new TwitterOAuth(consumerKey, consumerSecret, accessToken, accessSecret);
            api.MyUserInfo = api.getMyUserInfo();
            api.Status     = api.MyUserInfo == null ? UserStatus.INVALID_CREDITIONAL : UserStatus.LOGIN_SUCCESS;

            return(api);
        }