コード例 #1
0
        /// <summary>
        /// 发布信息
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        public static Boolean PublishTencent(string appKey, string appSecret, string content, string pic)
        {
            OAuth oauth = new OAuth(appKey, appSecret);

            //获取请求Token
            if (oauth.GetRequestToken(null))
            {
                NCLogger.GetInstance().WriteDebugLog("获取Request Token成功。值如下:");
                NCLogger.GetInstance().WriteDebugLog(String.Format("TokenKey={0}", oauth.Token));
                NCLogger.GetInstance().WriteDebugLog(String.Format("TokenSecret={0}", oauth.TokenSecret));
                NCLogger.GetInstance().WriteDebugLog("正在请求授权, 请在授权后,将页面提示的授权码码输入下面并继续……");
                Process.Start("https://open.t.qq.com/cgi-bin/authorize?oauth_token=" + oauth.Token);
                Console.Write("授权码:");
                string verifier = Console.ReadLine();
                string name;
                if (oauth.GetAccessToken(verifier, out name))
                {
                    NCLogger.GetInstance().WriteDebugLog("获取Access Token成功。值如下:");
                    NCLogger.GetInstance().WriteDebugLog(String.Format("TokenKey={0}", oauth.Token));
                    NCLogger.GetInstance().WriteDebugLog(String.Format("TokenSecret={0}", oauth.TokenSecret));
                    NCLogger.GetInstance().WriteDebugLog(String.Format("微博帐户名={0}", name));
                }
                else
                {
                    NCLogger.GetInstance().WriteDebugLog(String.Format("获取Access Token时出错,错误信息: {0}", oauth.LastError));
                }
            }
            else
            {
                NCLogger.GetInstance().WriteDebugLog(String.Format("获取Request Token时出错,错误信息: {0}", oauth.LastError));
            }

            if (oauth.LastError != null)
            {
                return(false);
            }
            Twitter twitter = new Twitter(oauth);
            var     data    = twitter.Add(content, pic, "127.0.0.1");

            if (data.Ret == 0)
            {
                //删除刚发的微博
                //data = twitter.Delete(((TweetOperateResult)data).TweetId);
                return(true);
            }
            //Console.WriteLine(data.Ret);
            //Console.Read();
            return(false);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="appKey"></param>
        /// <param name="appSecret"></param>
        public static void Run(string appKey, string appSecret)
        {
            OAuth oauth = new OAuth(appKey, appSecret);

            //获取请求Token
            if (oauth.GetRequestToken(null))
            {
                Console.WriteLine("获取Request Token成功。值如下:");
                Console.WriteLine("TokenKey={0}", oauth.Token);
                Console.WriteLine("TokenSecret={0}", oauth.TokenSecret);
                Console.WriteLine("正在请求授权, 请在授权后,将页面提示的授权码码输入下面并继续……");
                Process.Start("https://open.t.qq.com/cgi-bin/authorize?oauth_token=" + oauth.Token);
                Console.Write("授权码:");
                string verifier = Console.ReadLine();
                string name;
                if (oauth.GetAccessToken(verifier, out name))
                {
                    Console.WriteLine("获取Access Token成功。值如下:");
                    Console.WriteLine("TokenKey={0}", oauth.Token);
                    Console.WriteLine("TokenSecret={0}", oauth.TokenSecret);
                    Console.WriteLine("微博帐户名={0}", name);
                }
                else
                {
                    Console.WriteLine("获取Access Token时出错,错误信息: {0}", oauth.LastError);
                }
            }
            else
            {
                Console.WriteLine("获取Request Token时出错,错误信息: {0}", oauth.LastError);
            }

            if (oauth.LastError != null)
            {
                Console.Read();
                return;
            }
            Twitter twitter = new Twitter(oauth);
            var     data    = twitter.Add("#TXOpenTSDK# 测试发带图片的微博....", @"pic.jpg", "127.0.0.1");

            if (data.Ret == 0)
            {
                //删除刚发的微博
                data = twitter.Delete(((TweetOperateResult)data).TweetId);
            }
            Console.WriteLine(data.Ret);
            Console.Read();
        }