Exemplo n.º 1
0
        protected override void OnConfigUrlEncoder(string actionKey, UrlEncoder urlEncoder, params object[] param)
        {
            switch (actionKey)
            {
            case SettingModel.act_usershow:
                urlEncoder.Add("uid", param[0].ToString());
                if (param.Length > 1)
                {
                    urlEncoder.Add("screen_name", param.ToString());
                }
                break;

            case SettingModel.act_statusesFriendsTimeLine:
            case SettingModel.act_commentShow:
                urlEncoder.Add("count", PageCount.ToString());
                long prevID = long.Parse(param[0].ToString());
                long nextID = long.Parse(param[1].ToString());
                if (nextID != -1)
                {
                    urlEncoder.Add("max_id", nextID.ToString());
                }
                if (param.Length > 2)
                {
                    Dictionary <string, string> dic = param[2] as Dictionary <string, string>;
                    foreach (var item in dic)
                    {
                        urlEncoder.Add(item.Key, item.Value);
                    }
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        public async Task <Account> LoginWithToken(string baseUrl)
        {
            Uri    uri      = new Uri(baseUrl);
            var    names    = HttpUtility.ParseQueryString(uri.Query);
            string key      = "code";
            bool   hasToken = names.ContainsKey(key);

            if (hasToken)
            {
                UrlEncoder urlEncoder  = new UrlEncoder();
                string     code        = "code";
                Setting    access_toke = SettingModel.Action[SettingModel.act_access_token];
                string     url         = access_toke.Extras[0].Value + access_toke.Value;

                var p = CreateHttpParams(url, HttpMethod.Post, false);
                urlEncoder.Add(code, names[key]);
                urlEncoder.Add(SettingModel.act_client_id, App.ClientID);
                urlEncoder.Add("client_secret", SettingModel.Action[SettingModel.act_app_secret].Value);
                urlEncoder.Add("grant_type", "authorization_code");
                urlEncoder.Add("redirect_uri", SettingModel.Action[SettingModel.act_callback_url].Value);
                this.ConfigUrlParams(urlEncoder);

                string str = urlEncoder.ToString();
                p.Content     = Encoding.UTF8.GetBytes(str);
                p.ContentType = "application/x-www-form-urlencoded";
                StringContent content = new StringContent(str, Encoding.UTF8, "application/x-www-form-urlencoded");
                p.HttpContent = content;

                Token token = await this.Get <Token>(p);

                Account account = new Account();
                account.Token     = token;
                account.TokenCode = code;
                return(account);
            }
            return(null);
        }