public Form1(string[] param) { if (File.Exists(_TOKEN_FILE_PATH)) { if (File.ReadAllText(_TOKEN_FILE_PATH).Length > 0) { Token = new Token(); string str = File.ReadAllText(_TOKEN_FILE_PATH); var t = str.Split(' '); Token.AccessToken = t[0]; Token.ExpiresIn = Convert.ToInt32(t[1]); Token.UserId = Convert.ToInt32(t[2]); } } wc.Encoding = Encoding.UTF8; if (Token == null) { while (true) { LoginForm lf = new LoginForm(); if (lf.ShowDialog() == DialogResult.OK) { Token = lf.Token; File.WriteAllText(_TOKEN_FILE_PATH, lf.Token.AccessToken + " " + lf.Token.ExpiresIn + " " + lf.Token.UserId); break; } } } InitializeComponent(); if (param.Length > 0) { tbCode.Text = File.ReadAllText(param[0]); } tbToken.Text = Token.AccessToken; }
void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { string url = e.Url.ToString(); if (url.IndexOf("access_token") != -1) { int pos1 = url.IndexOf("access_token=") + "access_token=".Length; int pos2 = url.IndexOf('&', pos1); string token = url.Substring(pos1, pos2 - pos1); pos1 = url.IndexOf("expires_in=") + "expires_in=".Length; pos2 = url.IndexOf("&", pos1); int expires_in = Convert.ToInt32(url.Substring(pos1, pos2 - pos1)); int user_id = Convert.ToInt32(url.Substring(url.IndexOf("user_id=") + "user_id=".Length)); Token = new VKScriptEval.Token(); Token.AccessToken = token; Token.ExpiresIn=expires_in; Token.UserId = user_id; DialogResult = DialogResult.OK; Close(); } }