Example #1
0
    public TwitterService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
        info = new TwitterClientInfo() { ClientName = "Dropthings", ClientVersion = "1.0" };
    }
Example #2
0
        private void CheckForOrders(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(Password.Password) == false)
            {
                long lastOrderNum = Settings.Default.LastOrder;

                //Twitter Bug, t'aint me.
                if (lastOrderNum == 0) lastOrderNum = 1;

                TwitterClientInfo info = new TwitterClientInfo() { ClientName = "TweetSandwich", ClientVersion = "1.0" };
                var replies = FluentTwitter.CreateRequest(info)
                        .AuthenticateAs(twitterUserName.Text, Password.Password)
                        .Statuses()
                        .Replies()
                        .Since(lastOrderNum)
                        .AsJson();
                LogMessage(String.Format("Making request: {0}", replies.ToString()));

                IEnumerable<TwitterStatus> statuses = replies.Request().AsStatuses();
                if (statuses != null)
                {
                    var statusesFiltered = from d in statuses
                                           where d.Id > lastOrderNum
                                           where d.Text.IndexOf(orderString.Text, StringComparison.OrdinalIgnoreCase) != -1
                                           orderby d.CreatedDate descending
                                           select d;

                    //XDocument doc = XDocument.Parse(result);
                    //var statuses = (from d in doc.Descendants("status")
                    //                where int.Parse(d.Element("id").Value) > lastOrderNum
                    //                where d.Element("text").Value.Contains(orderString.Text)
                    //                select new
                    //                {
                    //                    tweetid = int.Parse(d.Element("id").Value),
                    //                    name = d.Element("user").Element("name").Value,
                    //                    location = d.Element("user").Element("location").Value,
                    //                    tweet = d.Element("text").Value,
                    //                    dateTime = d.Element("created_at").Value.ParseTwitterDateTime()
                    //                }).OrderByDescending(t => t.dateTime);

                    if (statusesFiltered.Count() > 0)
                    {
                        Settings.Default.LastOrder = statusesFiltered.Max(i => i.Id);
                        Settings.Default.Save();
                        System.Media.SystemSounds.Exclamation.Play();
                        PrintOrders(statusesFiltered);
                    }

                }
                else
                {
                    LogMessage("No orders.");
                }

            }
        }
Example #3
0
        public TwitterService(NetworkCredential credential)
        {
            this._info = new TwitterClientInfo();
            this._info.ClientName = "SurfaceTwitterApp";
            this._info.ClientVersion = "0.1";
            this._info.ClientUrl = "http://www.t-systems-mms.com/surface";

            this._credentials = credential;

            var twitter = FluentTwitter.CreateRequest()
                          .AuthenticateAs(this._credentials.UserName, this._credentials.Password)
                          .Statuses().Replies().AsXml();

            var response = twitter.Request();
            CheckXmlResponseForErrors(response);

            this.IsAuthenticated = true;
        }
        public TwitterService(NetworkCredential credential)
        {
            this._info               = new TwitterClientInfo();
            this._info.ClientName    = "SurfaceTwitterApp";
            this._info.ClientVersion = "0.1";
            this._info.ClientUrl     = "http://www.t-systems-mms.com/surface";

            this._credentials = credential;

            var twitter = FluentTwitter.CreateRequest()
                          .AuthenticateAs(this._credentials.UserName, this._credentials.Password)
                          .Statuses().Replies().AsXml();

            var response = twitter.Request();

            CheckXmlResponseForErrors(response);

            this.IsAuthenticated = true;
        }
Example #5
0
        protected Service(OAuthToken currentUserToken)
        {
            if (currentUserToken == null)
            {
                throw new NullReferenceException("currentUserToken");
            }

            var info = new TwitterClientInfo
            {
                ConsumerKey    = OAuth.GetOAuthSecrets().Key,
                ConsumerSecret = OAuth.GetOAuthSecrets().Secret,
            };


            _service = new TwitterServiceEx(info);
            _service.AuthenticateWith(currentUserToken.Token, currentUserToken.TokenSecret);


            _service.CacheWith(null);


            _currentUserToken = currentUserToken;
        }
Example #6
0
    private void DoWhatThisAppNeedToDo()
    {
        DataTable dt = new DataTable();
        DataRow   dr = null;

        dt.Columns.Add(new DataColumn("No.", typeof(string)));
        dt.Columns.Add(new DataColumn("Name", typeof(string)));
        dt.Columns.Add(new DataColumn("Location", typeof(string)));
        dt.Columns.Add(new DataColumn("Tweet", typeof(string)));
        dt.Columns.Add(new DataColumn("Semantic_Polarity", typeof(string)));



        //Client client = new Client("9091d4c1", "88e03d5f1f488db656ed6ab5d4a7a91e");

        TwitterClientInfo twitterClientInfo = new TwitterClientInfo();

        twitterClientInfo.ConsumerKey    = "zTYSSCTEaxfjXUAAxqE5hkTDx";
        twitterClientInfo.ConsumerSecret = "GO2ljEUk03MpA1b4F9vsHAXhLeDM57UMYdXwyR0Uz8pwk2tywm";

        TwitterService service = new TwitterService(twitterClientInfo);

        service.AuthenticateWith("368763386-jUH3zTuxEELZtdLsS8Eunxw7Q0mBbtnwhOQlZSAg",
                                 "BirOQsuX3LfXLTYAgI04ueSKNbPLIKbHGplwx2QB1ufCr");


        SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();
        SentimentAnalysisResults   score    = null;

        string maxid = "100000"; // dummy value

        string count         = "50";
        string sentiment     = "";
        int    tweetcount    = 1;
        int    positiveCount = 0;
        int    negativeCount = 0;
        int    neutralCount  = 0;

        if (maxid != null)
        {
            var tweets =
                service.Search(new SearchOptions
            {
                Q          = searchText,
                Count      = Convert.ToInt32(count),
                Lang       = "en",
                Resulttype = TwitterSearchResultType.Mixed
            });

            List <TwitterStatus> resultList = new List <TwitterStatus>(tweets.Statuses);
            maxid = resultList.Last().IdStr;

            if (tweets != null)
            {
                foreach (var tweet in tweets.Statuses)
                {
                    if (tweet.Text != null)
                    {
                        try
                        {
                            score = analyzer.PolarityScores(tweet.Text);
                        }
                        catch (Exception e)
                        {
                            Response.Write("<script>alert('" + e.Message + "')</script>");
                        }
                    }

                    if (tweet.Text.Contains("🙂") || tweet.Text.Contains("❤ī¸") || tweet.Text.Contains("👍") || tweet.Text.Contains("😡"))
                    {
                        sentiment = "positive";
                    }
                    else if (tweet.Text.Contains("😛") || tweet.Text.Contains("😠") || tweet.Text.Contains("😡") || tweet.Text.Contains("☚ī¸") || tweet.Text.Contains("👎"))
                    {
                        sentiment = "negative";
                    }
                    else
                    {
                        try
                        {
                            if (score.Compound > 0)
                            {
                                sentiment = "positive";
                            }
                            else if (score.Compound < 0)
                            {
                                sentiment = "negative";
                            }
                            else
                            {
                                sentiment = "neutral";
                            }
                        }
                        catch (Exception e)
                        {
                        }
                    }

                    if (sentiment == "positive")
                    {
                        positiveCount++;
                    }
                    else if (sentiment == "negative")
                    {
                        negativeCount++;
                    }
                    else if (sentiment == "neutral")
                    {
                        neutralCount++;
                    }



                    dr = dt.NewRow();

                    dr["No."]      = tweetcount;
                    dr["Name"]     = tweet.User.Name;
                    dr["Location"] = tweet.User.Location;
                    dr["Tweet"]    = tweet.Text;
                    if (tweet.Text != null)
                    {
                        dr["Semantic_Polarity"] = sentiment;
                    }
                    dt.Rows.Add(dr);
                    //ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                    tweetcount++;
                }
            }
            else
            {
                Response.Write("<script>alert('Fail')</script>");
            }

            while (maxid != null && tweetcount < Convert.ToInt32(count))
            {
                maxid  = resultList.Last().IdStr;
                tweets =
                    service.Search(new SearchOptions
                {
                    Q          = searchText,
                    Count      = Convert.ToInt32(count),
                    MaxId      = Convert.ToInt64(maxid),
                    Lang       = "en",
                    Resulttype = TwitterSearchResultType.Mixed
                });                                //resultList = new List<TwitterStatus>(tweets_search.Statuses);
                foreach (var tweet in tweets.Statuses)
                {
                    try
                    {
                        if (tweet.Text != null)
                        {
                            try
                            {
                                score = analyzer.PolarityScores(tweet.Text);
                            }
                            catch (Exception e)
                            {
                            }
                        }

                        dr = dt.NewRow();
                        if (tweet.Text.Contains("🙂") || tweet.Text.Contains(":)") || tweet.Text.Contains(":-)") || tweet.Text.Contains("❤ī¸") || tweet.Text.Contains("👍"))
                        {
                            sentiment = "positive";
                        }
                        else if (tweet.Text.Contains("😛") || tweet.Text.Contains(":P") || tweet.Text.Contains(":-P") || tweet.Text.Contains("😠") || tweet.Text.Contains("😡") || tweet.Text.Contains("☚ī¸") || tweet.Text.Contains("👎"))
                        {
                            sentiment = "negative";
                        }
                        else
                        {
                            try
                            {
                                if (score.Compound > 0)
                                {
                                    sentiment = "positive";
                                }
                                else if (score.Compound < 0)
                                {
                                    sentiment = "negative";
                                }
                                else
                                {
                                    sentiment = "neutral";
                                }
                            }

                            catch (Exception e)
                            {
                            }
                        }

                        if (sentiment == "positive")
                        {
                            positiveCount++;
                        }
                        else if (sentiment == "negative")
                        {
                            negativeCount++;
                        }
                        else if (sentiment == "neutral")
                        {
                            neutralCount++;
                        }

                        dr["No."]      = tweetcount;
                        dr["Name"]     = tweet.User.Name;
                        dr["Location"] = tweet.User.Location;
                        dr["Tweet"]    = tweet.Text;
                        if (tweet.Text != null)
                        {
                            dr["Semantic_Polarity"] = sentiment;
                        }
                        dt.Rows.Add(dr);
                        //ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                        tweetcount++;
                    }
                    catch { }
                }
            }
        }


        double total = positiveCount + negativeCount + neutralCount;

        double postivePercentage  = (positiveCount / total) * 100;
        double negativePercentage = (negativeCount / total) * 100;
        double neutralPercentage  = (neutralCount / total) * 100;

        postiveTextBox.Visible  = true;
        negativeTextBox.Visible = true;
        neutralTextBox.Visible  = true;

        postiveTextBox.Text  = postivePercentage.ToString() + "%";
        negativeTextBox.Text = negativePercentage.ToString() + "%";
        neutralTextBox.Text  = neutralPercentage.ToString() + "%";



        ViewState["CurrentTable"] = dt;

        GridView1.DataSource = dt;
        GridView1.DataBind();
        Page.ClientScript.RegisterStartupScript(
            GetType(),
            "4444",
            "showGraph(" + positiveCount + "," + negativeCount + "," + neutralCount + ");",
            true);
    }
Example #7
0
        private void oAuthExecute()
        {
            _consumerKey = ConfigurationManager.AppSettings["consumerKey"];
            _consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

            TwitterClientInfo myClientInfo = new TwitterClientInfo();
            myClientInfo.ClientName = "TwistHelloKitty";
            myClientInfo.ClientUrl = "http://www.hellokittyland.com";
            myClientInfo.ClientVersion = "0.0.0.1";
            myClientInfo.ConsumerKey = _consumerKey;
            myClientInfo.ConsumerSecret = _consumerSecret;

            FluentTwitter.SetClientInfo(myClientInfo);

            requestToken = HttpContext.Request["oauth_token"];

            if (requestToken == null && ( Session["accessToken"] == null))
            {
                var request = GetRequestToken();
                // retrieve a URL used to direct the user to authorize, and
                // return to this page with a token

                var authorizeUrl = FluentTwitter.CreateRequest().Authentication.GetAuthorizationUrl(request.Token, "http://localhost:1113");
                Response.Redirect(authorizeUrl);
            }
            else
            {
                // exchange returned request token for access token
                if (access==null)
                access = GetAccessToken(requestToken);
                UserManager.GrantToken(access);
                // make an oauth-authenticated call with the access token,
                // and remember you need to persist this token for this user&apos;s auth
                //var query = FluentTwitter.CreateRequest().AuthenticateWith(_consumerKey, _consumerSecret, access.Token, access.TokenSecret)
                //    .Account().VerifyCredentials().AsXml();
                //// use as normal
                //var response = query.Request();
                //GetResponse(response);
            }
        }
    private void DoWhatThisAppNeedToDo()
    {
        DataTable dt = new DataTable();
        DataRow   dr = null;

        dt.Columns.Add(new DataColumn("No.", typeof(string)));
        dt.Columns.Add(new DataColumn("Name", typeof(string)));
        dt.Columns.Add(new DataColumn("Location", typeof(string)));
        dt.Columns.Add(new DataColumn("Tweet", typeof(string)));
        dt.Columns.Add(new DataColumn("Semantic_Polarity", typeof(string)));



        //Client client = new Client("9091d4c1", "88e03d5f1f488db656ed6ab5d4a7a91e");

        TwitterClientInfo twitterClientInfo = new TwitterClientInfo();

        twitterClientInfo.ConsumerKey    = "jfaKfFmSdtvZRAwO8waULkGqK";
        twitterClientInfo.ConsumerSecret = "4a9RpM2ujRJb9WoE3avzwvvNUyjQC0ox3e0mess2YBAmcuV7MD";

        TwitterService service = new TwitterService(twitterClientInfo);

        service.AuthenticateWith("368763386-jgygtatu9MZLGeEvR6pbGKvL1rjLSapSW6Q5Dq5m",
                                 "BZl9edQUEk6uGpeLi63gXGzcae1kOSpdTNi3kyrio9VLT");


        //Sentiment sentiment = null;

        string maxid = "100000"; // dummy value

        string count         = "50";
        string polarity      = "";
        int    tweetcount    = 1;
        int    positiveCount = 0;
        int    negativeCount = 0;
        int    neutralCount  = 0;

        if (maxid != null)
        {
            var tweets =
                service.Search(new SearchOptions
            {
                Q          = searchText,
                Count      = Convert.ToInt32(count),
                Lang       = "en",
                Resulttype = TwitterSearchResultType.Mixed
            });

            List <TwitterStatus> resultList = new List <TwitterStatus>(tweets.Statuses);
            maxid = resultList.Last().IdStr;


            if (tweets != null)
            {
                foreach (var tweet in tweets.Statuses)
                {
                    if (tweet.Text != null)
                    {
                        //sentiment = client.Sentiment(text: tweet.Text);
                    }

                    if (tweet.Text.Contains("🙂") || tweet.Text.Contains("❤ī¸") || tweet.Text.Contains("👍") || tweet.Text.Contains("😡"))
                    {
                        polarity = "positive";
                    }
                    else if (tweet.Text.Contains("😛") || tweet.Text.Contains("😠") || tweet.Text.Contains("😡") || tweet.Text.Contains("☚ī¸") || tweet.Text.Contains("👎"))
                    {
                        polarity = "negative";
                    }
                    else
                    {
                        //polarity = sentiment.Polarity;
                    }

                    if (polarity == "positive")
                    {
                        positiveCount++;
                    }
                    else if (polarity == "negative")
                    {
                        negativeCount++;
                    }
                    else if (polarity == "neutral")
                    {
                        neutralCount++;
                    }



                    dr = dt.NewRow();

                    dr["No."]      = tweetcount;
                    dr["Name"]     = tweet.User.Name;
                    dr["Location"] = tweet.User.Location;
                    dr["Tweet"]    = tweet.Text;
                    if (tweet.Text != null)
                    {
                        dr["Semantic_Polarity"] = ""; //polarity;
                    }
                    dt.Rows.Add(dr);
                    //ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                    tweetcount++;
                }
            }
            else
            {
                Response.Write("<script>alert('Fail')</script>");
            }

            while (maxid != null && tweetcount < Convert.ToInt32(count))
            {
                maxid  = resultList.Last().IdStr;
                tweets =
                    service.Search(new SearchOptions
                {
                    Q          = searchText,
                    Count      = Convert.ToInt32(count),
                    MaxId      = Convert.ToInt64(maxid),
                    Lang       = "en",
                    Resulttype = TwitterSearchResultType.Mixed
                });                                //resultList = new List<TwitterStatus>(tweets_search.Statuses);
                foreach (var tweet in tweets.Statuses)
                {
                    try
                    {
                        if (tweet.Text != null)
                        {
                            //sentiment = client.Sentiment(text: tweet.Text);
                        }

                        dr = dt.NewRow();
                        if (tweet.Text.Contains("🙂") || tweet.Text.Contains(":)") || tweet.Text.Contains(":-)") || tweet.Text.Contains("❤ī¸") || tweet.Text.Contains("👍"))
                        {
                            polarity = "positive";
                        }
                        else if (tweet.Text.Contains("😛") || tweet.Text.Contains(":P") || tweet.Text.Contains(":-P") || tweet.Text.Contains("😠") || tweet.Text.Contains("😡") || tweet.Text.Contains("☚ī¸") || tweet.Text.Contains("👎"))
                        {
                            polarity = "negative";
                        }
                        else
                        {
                            //polarity = sentiment.Polarity;
                        }

                        if (polarity == "positive")
                        {
                            positiveCount++;
                        }
                        else if (polarity == "negative")
                        {
                            negativeCount++;
                        }
                        else if (polarity == "neutral")
                        {
                            neutralCount++;
                        }

                        dr["No."]      = tweetcount;
                        dr["Name"]     = tweet.User.Name;
                        dr["Location"] = tweet.User.Location;
                        dr["Tweet"]    = tweet.Text;
                        if (tweet.Text != null)
                        {
                            dr["Semantic_Polarity"] = ""; //polarity;
                        }
                        dt.Rows.Add(dr);
                        //ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
                        tweetcount++;
                    }
                    catch { }
                }
            }
        }


        /*double total = positiveCount + negativeCount + neutralCount;
         *
         * double postivePercentage = (positiveCount / total) * 100;
         * double negativePercentage = (negativeCount / total) * 100;
         * double neutralPercentage = (neutralCount / total) * 100;
         *
         * postiveTextBox.Visible = true;
         * negativeTextBox.Visible = true;
         * neutralTextBox.Visible = true;
         *
         * postiveTextBox.Text = postivePercentage.ToString()+"%";
         * negativeTextBox.Text= negativePercentage.ToString()+"%";
         * neutralTextBox.Text=neutralPercentage.ToString()+"%";*/



        ViewState["CurrentTable"] = dt;

        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
Example #9
0
        private void CheckForOrders(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Settings.Default.Token) && !String.IsNullOrEmpty(Settings.Default.Secret))
            {
                long lastOrderNum = Settings.Default.LastOrder;

                //Twitter Bug, t'aint me.
                if (lastOrderNum == 0) lastOrderNum = 1;

                TwitterClientInfo info = new TwitterClientInfo() { ClientName = "TweetSandwich", ClientVersion = "1.0" };

                var replies = FluentTwitter.CreateRequest(info)
                        .AuthenticateWith(consumerKey, consumerSecret, Settings.Default.Token, Settings.Default.Secret)
                        .Statuses()
                        .Mentions()
                        .Since(lastOrderNum)
                        .AsJson();
                LogMessage(String.Format("Making request: {0}", replies.ToString()));

                IEnumerable<TwitterStatus> statuses = replies.Request().AsStatuses();
                if (statuses != null)
                {
                    var statusesFiltered = from d in statuses
                                           where d.Id > lastOrderNum
                                           where d.Text.IndexOf(orderString.Text, StringComparison.OrdinalIgnoreCase) != -1
                                           orderby d.CreatedDate descending
                                           select d;

                    if (statusesFiltered.Count() > 0)
                    {
                        Settings.Default.LastOrder = statusesFiltered.Max(i => i.Id);
                        Settings.Default.Save();
                        System.Media.SystemSounds.Exclamation.Play();
                        PrintOrders(statusesFiltered);
                    }

                }
                else
                {
                    LogMessage("No orders.");
                }

            }
        }