Example #1
0
        public void getSinaClient()
        {
            string code = "";

            if (string.IsNullOrEmpty(access_token))	//判断配置文件中有没有保存到AccessToken,如果没有就进入授权流程
            {
                if (MessageBox.Show("新浪微博未授权或授权已过期,请重新授权!", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                {
                    Forms.SinaWBOauth sinaWbForm = new Forms.SinaWBOauth();
                    sinaWbForm.thread_in = "1";
                    if (sinaWbForm.ShowDialog() == DialogResult.OK)
                    {
                        if (sinaWbForm.retrun_url.Contains("code="))
                        {
                            string[] url = sinaWbForm.retrun_url.Split('=');
                            if (url.Length > 0) { code = url[1]; }
                            oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
                            at = oauth.GetAccessTokenByAuthorizationCode(code);
                            xmlutil.SetValue("AccessToken", at.Token);
                            sina = new Client(new OAuth(app_key, app_secret, at.Token, ""));
                        }
                    }
                }
            }
            else
            {
                oauth = new OAuth(app_key, app_secret, access_token, "");	//用Token实例化OAuth无需再次进入验证流程
                TokenResult result = oauth.VerifierAccessToken();
                if (result == TokenResult.Success)
                {
                    sina = new Client(oauth);
                }
            }
        }
Example #2
0
        public void getSinaClient()
        {
            string code = "";

            if (string.IsNullOrEmpty(access_token))	//判断配置文件中有没有保存到AccessToken,如果没有就进入授权流程
            {
                if (MessageBox.Show("新浪微博未授权或授权已过期,请重新授权!", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                {
                    Forms.SinaWBOauth sinaWbForm = new Forms.SinaWBOauth();
                    sinaWbForm.thread_in = "1";
                    if (sinaWbForm.ShowDialog() == DialogResult.OK)
                    {
                        if (sinaWbForm.retrun_url.Contains("code="))
                        {
                            string[] url = sinaWbForm.retrun_url.Split('=');
                            if (url.Length > 0) { code = url[1]; }
                            oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
                            at = oauth.GetAccessTokenByAuthorizationCode(code);
                            xmlutil.SetValue("AccessToken", at.Token);
                            sina = new Client(new OAuth(app_key, app_secret, at.Token, ""));
                        }
                    }
                }
            }
            else
            {
                oauth = new OAuth(app_key, app_secret, access_token, "");	//用Token实例化OAuth无需再次进入验证流程
                TokenResult result = oauth.VerifierAccessToken();
                if (result == TokenResult.Success)
                {
                    sina = new Client(oauth);
                }
            }
        }