Пример #1
0
        //
        // GET: /Home/

        public string AjaxSaveToDB()
        {
            if (Session["LoggedASP"] != null)
            {
                TimelineOptions options = new TimelineOptions();

                options.Count           = 200;
                options.IncludeRetweets = true;

                OAuthTokens token = new OAuthTokens();
                token.ConsumerKey       = ConfigurationManager.AppSettings["consumerKey"];
                token.ConsumerSecret    = ConfigurationManager.AppSettings["consumerSecret"];
                token.AccessToken       = ((User)Session["LoggedUser"]).TwitterToken;
                token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                TwitterResponse <TwitterStatusCollection> truc = TwitterTimeline.HomeTimeline(token, options);

                TweetEntity tweetEntity = new TweetEntity();

                tweetEntity.RemoveTweetFromOwner(((User)Session["LoggedUser"]).ID);

                foreach (var item in truc.ResponseObject)
                {
                    //int lol = ;

                    tweetEntity.AddTweet(item.Id, item.Text, item.User.ScreenName, item.User.ProfileImageLocation, ((User)Session["LoggedUser"]).ID, ((int)((TimeSpan)(item.CreatedDate - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime())).TotalSeconds));
                }
                return("Success");
            }
            else
            {
                return("Fail");
            }
        }
Пример #2
0
        /// <summary>
        /// Gets current user (defined by access token) home timeline
        /// </summary>
        /// <param name="messageCount">Message count</param>
        /// <returns>Message list</returns>
        public List <Message> GetUserHomeTimeLine(int messageCount)
        {
            try
            {
                Twitterizer.OAuthTokens tokens = GetOAuthTokens();

                Twitterizer.UserTimelineOptions options = new Twitterizer.UserTimelineOptions();
                options.Count           = messageCount;
                options.IncludeRetweets = true;

                TwitterResponse <TwitterStatusCollection> statusResponse = TwitterTimeline.HomeTimeline(tokens, options);

                if (statusResponse.Result == RequestResult.Success)
                {
                    return(MapMessage(statusResponse.ResponseObject));
                }

                else
                {
                    throw CreateException(statusResponse.Result, statusResponse.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }
        public static void HomeTimeline()
        {
            OAuthTokens tokens = Configuration.GetTokens();

            TwitterResponse <TwitterStatusCollection> timelineResponse = TwitterTimeline.HomeTimeline(tokens);

            PerformCommonTimelineTests(timelineResponse);
        }
Пример #4
0
        public void SSL()
        {
            TwitterResponse <TwitterUser> sslUser = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = true
            });

            Assert.IsTrue(sslUser.RequestUrl.StartsWith("https://"), "sslUser connection should be SSL");

            TwitterResponse <TwitterUser> user = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = false
            });

            Assert.IsTrue(user.RequestUrl.StartsWith("http://"), "user connection should not be SSL");

            TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.HomeTimeline(Configuration.GetTokens(), new TimelineOptions {
                UseSSL = true
            });

            Assert.IsTrue(timeline.RequestUrl.StartsWith("https://"), "timeline connection should be SSL");
        }
Пример #5
0
        public static void SSL()
        {
            TwitterResponse <TwitterUser> sslUser = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = true
            });

            Assert.That(sslUser.RequestUrl.StartsWith("https://"));

            TwitterResponse <TwitterUser> user = TwitterUser.Show("twitterapi", new OptionalProperties {
                UseSSL = false
            });

            Assert.That(user.RequestUrl.StartsWith("http://"));

            TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.HomeTimeline(Configuration.GetTokens(), new TimelineOptions {
                UseSSL = true
            });

            Assert.That(timeline.RequestUrl.StartsWith("https://"));
            Assert.That(user.RequestUrl.StartsWith("https://"));
        }
        public static void Home()
        {
            OAuthTokens tokens = Configuration.GetTokens();

            TwitterResponse <TwitterStatusCollection> response = TwitterTimeline.HomeTimeline(tokens);

            Assert.IsNotNull(response);
            Assert.That(response.Result == RequestResult.Success);
            Assert.IsNotNull(response.ResponseObject);
            Assert.That(response.ResponseObject.Count > 0);

            decimal firstId = response.ResponseObject[0].Id;

            response = TwitterTimeline.HomeTimeline(tokens, new TimelineOptions {
                Page = ++response.ResponseObject.Page
            });
            Assert.IsNotNull(response);
            Assert.That(response.Result == RequestResult.Success);
            Assert.IsNotNull(response.ResponseObject);
            Assert.That(response.ResponseObject.Count > 0);
            Assert.AreNotEqual(response.ResponseObject[0].Id, firstId);
        }
Пример #7
0
        public void Home()
        {
            OAuthTokens tokens = Configuration.GetTokens();

            TwitterResponse <TwitterStatusCollection> response = TwitterTimeline.HomeTimeline(tokens);

            Assert.IsNotNull(response, "response is null");
            Assert.IsTrue(response.Result == RequestResult.Success, response.ErrorMessage ?? response.Result.ToString());
            Assert.IsNotNull(response.ResponseObject, response.ErrorMessage ?? response.Result.ToString());
            Assert.IsTrue(response.ResponseObject.Count > 0, response.ErrorMessage ?? response.Result.ToString());

            decimal firstId = response.ResponseObject[0].Id;

            response = TwitterTimeline.HomeTimeline(tokens, new TimelineOptions {
                Page = ++response.ResponseObject.Page
            });
            Assert.IsNotNull(response, "response is null");
            Assert.IsTrue(response.Result == RequestResult.Success, response.ErrorMessage ?? response.Result.ToString());
            Assert.IsNotNull(response.ResponseObject, response.ErrorMessage ?? response.Result.ToString());
            Assert.IsTrue(response.ResponseObject.Count > 0, response.ErrorMessage ?? response.Result.ToString());
            Assert.AreNotEqual(response.ResponseObject[0].Id, firstId, response.ErrorMessage ?? response.Result.ToString());
        }
Пример #8
0
        private void getUserTimeline(string username)
        {
            getWaitCursor();
            TimelineOptions options = new TimelineOptions();

            options.Count = 50;

            TwitterResponse <TwitterStatusCollection> timeline = TwitterTimeline.HomeTimeline(_authToken, options);

            if (timeline.Result == RequestResult.Success)
            {
                listboxHomeTimeline.Items.Clear();
                try
                {
                    //MessageBox.Show(timeline.ResponseObject);
                    for (int i = 0; i < timeline.ResponseObject.Count; i++)
                    {
                        var         result = timeline.ResponseObject[i];
                        ListBoxItem itm    = new ListBoxItem();
                        //itm.Name = result.User.ScreenName;
                        itm.Uid     = result.User.Id.ToString();;
                        itm.Content = result.User.ScreenName + ": " + result.Text + " " + result.CreatedDate;

                        listboxHomeTimeline.Items.Add(itm);
                    }
                }
                catch (TwitterizerException)
                {
                    MessageBox.Show("Erro");
                }
            }
            else
            {
                MessageBox.Show(timeline.ErrorMessage);
            }
            getDefaultCursor();
        }
Пример #9
0
        public ActionResult Index()
        {
            if (Session["LoggedASP"] != null && Session["DatabaseMode"] != null)
            {
                User myUser = (User)Session["LoggedUser"];
                ViewData["Username"] = myUser.Username;

                TweetEntity  entity = new TweetEntity();
                List <Tweet> list   = entity.GetTweetsForOwner(((User)Session["LoggedUser"]).ID);

                OAuthTokens token = new OAuthTokens();
                token.ConsumerKey       = ConfigurationManager.AppSettings["consumerKey"];
                token.ConsumerSecret    = ConfigurationManager.AppSettings["consumerSecret"];
                token.AccessToken       = ((User)Session["LoggedUser"]).TwitterToken;
                token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                //string loggedUserName = TwitterUser.Show(token, Decimal.Parse(((User)Session["LoggedUser"]).TwitterID)).ResponseObject.ScreenName.ToLower();

                if (list.Count != 0)
                {
                    foreach (var item in list)
                    {
                        ViewData["message"] += "<div class='message'><div class='editTweet'><a class='editTweetA' rel='" + item.ID.ToString() + "' href='/Tweet/EditGet/" + item.ID.ToString() + "'>Edit</a> <a class='deleteLink' href='/Tweet/Delete/" + item.IDTwitter.ToString() + "'>Delete</a></div><div class='tweetP'><img class='inTweetImg' src='" + item.Avatar + "' /><a href=\"/User/" + item.Username + "\">" + item.Username + "</a> ---- " + item.Text + "</div></div>";
                    }
                }
                else
                {
                    ViewData["message"] = "<p style='text-align: center;'>Aucun rang dans la base de donnée. :(</p>";
                }
                return(View());
            }
            else
            {
                if (Session["LoggedASP"] != null)
                {
                    User myUser = (User)Session["LoggedUser"];
                    ViewData["Username"] = myUser.Username;
                }

                if (Session["LoggedTwitter"] != null)
                {
                    TimelineOptions options = new TimelineOptions();

                    options.Count           = 200;
                    options.IncludeRetweets = true;

                    OAuthTokens token = new OAuthTokens();
                    token.ConsumerKey       = ConfigurationManager.AppSettings["consumerKey"];
                    token.ConsumerSecret    = ConfigurationManager.AppSettings["consumerSecret"];
                    token.AccessToken       = ((User)Session["LoggedUser"]).TwitterToken;
                    token.AccessTokenSecret = ((User)Session["LoggedUser"]).TwitterTokenSecret;

                    try
                    {
                        TwitterResponse <TwitterStatusCollection> truc = TwitterTimeline.HomeTimeline(token, options);

                        foreach (var item in truc.ResponseObject)
                        {
                            ViewData["message"] += "<p class='tweetP'><img class='inTweetImg' src='" + item.User.ProfileImageLocation + "' /><a href=\"/User/" + item.User.ScreenName + "\">" + item.User.ScreenName + "</a> ---- " + item.Text + "</p>";
                        }
                    }
                    catch (WebException exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : " + exception.Message + "</p>";
                    }
                    catch (Exception exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : " + exception.Message + "</p>";
                    }
                }
                else
                {
                    if (Session["LoggedASP"] != null)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Bonjour " + ((User)Session["LoggedUser"]).Username + ", ton compte existe mais il n'est pas associé a un compte Twitter pour le moment, si tu veux associer ton compte Twitter avec ton Compte Tweetasse, rends toi sur la page Manage via le menu en haut.</p><hr />";
                    }

                    try
                    {
                        TwitterResponse <TwitterStatusCollection> publicTimeline = TwitterTimeline.PublicTimeline();
                        if (String.IsNullOrEmpty(publicTimeline.ErrorMessage))
                        {
                            foreach (var item in publicTimeline.ResponseObject)
                            {
                                ViewData["message"] += "<p class='tweetP'><img class='inTweetImg' src='" + item.User.ProfileImageLocation + "' /><a href=\"/User/" + item.User.ScreenName + "\">" + item.User.ScreenName + "</a> ---- " + item.Text + "</p>";
                            }
                        }
                        else
                        {
                            ViewData["message"] = "<p style='text-align:center;'>Bonjour shagasse, l'application a excedé le nombre de demandes maximum sur l'API Twitter Publique sans Login oAuth pour cette heure. Démerdes-toi, merssi!</p>";
                        }
                    }
                    catch (WebException exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : " + exception.Message + "</p>";
                        return(View());
                    }
                    catch (Exception exception)
                    {
                        ViewData["message"] = "<p style='text-align:center;'>Erreur : " + exception.Message + "</p>";
                    }
                }
                return(View());
            }
        }
Пример #10
0
 private void toolStripDropDownButton2_Click(object sender, EventArgs e)
 {
     toolStripStatusLabel1.Text = "Restarting...";
     ts.EndStream();
     timeline.Clear();
     if (st == StartType.UserStream)
     {
         ts.StartUserStream(null, new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, null, null, new EventCallback(x => { Event(x); }), null);
         var tt = TwitterTimeline.HomeTimeline(ts.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
             toolStripStatusLabel1.Text = "Restarted.";
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (st == StartType.FilterStream)
     {
         string query = "";
         if (ts.StreamOptions.Track.Count != 0)
         {
             foreach (string ss in ts.StreamOptions.Track)
             {
                 query += ss + "+AND+";
             }
             query = query.Remove(query.Length - 5, 5);
         }
         ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); }));
         var tt = TwitterSearch.Search(ts.Tokens, query, new SearchOptions()
         {
             ResultType = SearchOptionsResultType.Popular
         });
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(new TwitterStatus()
                 {
                     Text = tss.Text, User = new TwitterUser()
                     {
                         ScreenName = tss.FromUserScreenName
                     }
                 });
             }
             toolStripStatusLabel1.Text = "Restarted.";
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (st == StartType.Mentions)
     {
         ts.StreamOptions.Track.Add("@" + ExtendedOAuthTokens.Tokens.First <ExtendedOAuthTokens>((x) => { return(x.OAuthTokens == ts.Tokens); }).UserName);
         ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); }));
         var tt = TwitterTimeline.Mentions(ts.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
             toolStripStatusLabel1.Text = "Restarted.";
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     ShowF();
 }
Пример #11
0
 public Column(TwitterStream stream, StartType s, string title)
 {
     if (back != null)
     {
         listView1.BackgroundImage = back;
     }
     InitializeComponent();
     listView1.SmallImageList = new ImageList();
     ts = stream;
     if (s == StartType.UserStream)
     {
         ts.StartUserStream(null, new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, null, null, new EventCallback(x => { Event(x); }), null);
         var tt = TwitterTimeline.HomeTimeline(stream.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (s == StartType.FilterStream)
     {
         string query = "";
         if (ts.StreamOptions.Track.Count != 0)
         {
             foreach (string ss in ts.StreamOptions.Track)
             {
                 query += ss + "+AND+";
             }
             query = query.Remove(query.Length - 5, 5);
         }
         ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); }));
         var tt = TwitterSearch.Search(ts.Tokens, query, new SearchOptions()
         {
             ResultType = SearchOptionsResultType.Popular
         });
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(new TwitterStatus()
                 {
                     Text = tss.Text, User = new TwitterUser()
                     {
                         ScreenName = tss.FromUserScreenName
                     }
                 });
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (s == StartType.Mentions)
     {
         ts.StreamOptions.Track.Add("@" + ExtendedOAuthTokens.Tokens.First <ExtendedOAuthTokens>((x) => { return(x.OAuthTokens == ts.Tokens); }).UserName);
         ts.StartPublicStream(new StreamStoppedCallback((x) => { toolStripStatusLabel1.Text = "Stopped."; }), new StatusCreatedCallback(x => { Add(x); }), null, new EventCallback(x => { Event(x); }));
         var tt = TwitterTimeline.Mentions(stream.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     st        = s;
     this.Text = title;
     Columns.Add(this);
     ShowF();
 }
Пример #12
0
 public void Renew()
 {
     if (st == StartType.UserStream)
     {
         timeline.Clear();
         var tt = TwitterTimeline.HomeTimeline(ts.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (st == StartType.FilterStream)
     {
         string query = "";
         if (ts.StreamOptions.Track.Count != 0)
         {
             foreach (string ss in ts.StreamOptions.Track)
             {
                 query += ss + "+AND+";
             }
             query = query.Remove(query.Length - 5, 5);
         }
         timeline.Clear();
         var tt = TwitterSearch.Search(ts.Tokens, query, new SearchOptions()
         {
             ResultType = SearchOptionsResultType.Popular
         });
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(new TwitterStatus()
                 {
                     Text = tss.Text, User = new TwitterUser()
                     {
                         ScreenName = tss.FromUserScreenName
                     }
                 });
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     else if (st == StartType.Mentions)
     {
         timeline.Clear();
         var tt = TwitterTimeline.Mentions(ts.Tokens);
         try
         {
             foreach (var tss in tt.ResponseObject)
             {
                 timeline.Add(tss);
             }
         }
         catch
         {
             MessageBox.Show(tt.ErrorMessage);
         }
     }
     ShowF();
 }
Пример #13
0
 public TwitterStatusCollection GetTweets()
 {
     return(TwitterTimeline.HomeTimeline(privOAuth.GetOAuthToken()).ResponseObject);
 }