Exemple #1
0
        //-------------------------------------------------------------------------
        // ポスト(xAuth版)
        //-------------------------------------------------------------------------
        public bool Post(string iMessage,string iTopic)
        {
            if (Properties.Settings.Default.tw_token.Length == 0 ||
                Properties.Settings.Default.tw_token_secret.Length == 0)
                return false;

            if (iTopic.Length > 0)
                iMessage += " " + iTopic;

            oAuthTwitter oAuth = new oAuthTwitter();
            oAuth.Token = Properties.Settings.Default.tw_token;
            oAuth.TokenSecret = Properties.Settings.Default.tw_token_secret;
            string url = "http://twitter.com/statuses/update.xml";
            string xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode(iMessage));
            oAuth = null;
            return true;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = "";
            string xml = "";
            oAuthTwitter oAuth = new oAuthTwitter();

            if (Request["oauth_token"] == null)
            {
                //Redirect the user to Twitter for authorization.
                //Using oauth_callback for local testing.
                oAuth.CallBackUrl = Request.Url.AbsoluteUri;// "Default.aspx";
                Response.Redirect(oAuth.AuthorizationLinkGet());
            }
            else
            {
                //Get the access token and secret.
                oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
                if (oAuth.TokenSecret.Length > 0)
                {
                    //We now have the credentials, so make a call to the Twitter API.
                    url = "http://twitter.com/account/verify_credentials.xml";
                    xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
                    apiResponse.InnerHtml = Server.HtmlEncode(xml);

                    //POST Test
                    //url = "http://twitter.com/statuses/update.xml";
                    //xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode("Hello @monirabuhilal - Testing the .NET oAuth API"));
                    //apiResponse.InnerHtml = Server.HtmlEncode(xml);
                }
            }
            //POST Test
            url = "http://twitter.com/statuses/update.xml";
            //"Hello @monirabuhilal - Testing the .NET oAuth API http://bit.ly/Vote4Jo"
            xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode(Request["t"]));
            //apiResponse.InnerHtml = Server.HtmlEncode(xml);
            apiResponse.InnerHtml = "<script type='text/javascript'>window.opener='x';window.close();</script>";
        }