Remove the twitter authorization during program running in C#

78 views Asked by At

I am doing the tweets automatically from getting data from json url. But during the program execution after some seconds twitter always require to press the authorization button and then the program will continue. But now i want to place more than 10 urls in my program and it will create the heavy problem to press the authorization button all the time. Please help me in this regard to remove the authorization process every time. Below is the coding of the twitter by twitterizer.

[enter image description here][1]
public void twitter_function()
        {
            string x;
            var list2 = (List<string>)Session["title"];
            if (list2 == null)
            {
                x = "No new Products Found";
            }
            else
            {
                x = string.Join(",", list2);
                // x= list2[0];
            }
            //foreach (string x in list2)
            //{
            // Your code

            var oauth_consumer_key = "[REDACTED]";
            var oauth_consumer_secret = "[REDACTED]";

            if (Request["oauth_token"] == null)
            {
                OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(
                    oauth_consumer_key,
                    oauth_consumer_secret,
                    Request.Url.AbsoluteUri);   
                    Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}",
                    reqToken.Token));
            }
            else
            {
                string requestToken = Request["oauth_token"].ToString();
                string pin = Request["oauth_verifier"].ToString();

                var tokens = OAuthUtility.GetAccessToken(
                    oauth_consumer_key,
                    oauth_consumer_secret,
                    requestToken,
                    pin);
                OAuthTokens accesstoken = new OAuthTokens()
                {
                    AccessToken = tokens.Token,
                    AccessTokenSecret = tokens.TokenSecret,
                    ConsumerKey = oauth_consumer_key,
                    ConsumerSecret = oauth_consumer_secret
                };
                //TwitterResponse<TwitterStatus> response = TwitterStatus.Update(
                //    accesstoken,
                //    "Testing!! It works (hopefully).");

                Twitterizer.TwitterResponse<TwitterStatus> response = TwitterStatus.Update(accesstoken, x, new StatusUpdateOptions() { UseSSL = true, APIBaseAddress = "http://api.twitter.com/1.1/" });

                if (response.Result == RequestResult.Success)
                {
                    Response.Redirect("https://twitter.com/");
                }
                else
                {
                    Response.Redirect("https://twitter.com/");
                }
            }
        }

It is the coding for tweets and it requires "Authorize app" button every time. I want to remove it from program and want to run my program without any interruption. Thanks

0

There are 0 answers