public static void PublicTimeline()
        {
            TwitterStatusCollection timeline = TwitterTimeline.PublicTimeline().ResponseObject;

            Assert.IsNotNull(timeline);
            Assert.IsNotEmpty(timeline);

            Assert.That(timeline.Count > 0 && timeline.Count <= 20, "Timeline should contain between 0 and 20 items.");
        }
Esempio n. 2
0
        public void PublicTimeline()
        {
            var response = TwitterTimeline.PublicTimeline();

            Assert.IsNotNull(response.ResponseObject, response.ErrorMessage);
            Assert.AreNotEqual(0, response.ResponseObject.Count, response.ErrorMessage);

            Assert.IsTrue(response.ResponseObject.Count > 0 && response.ResponseObject.Count <= 20, "Timeline should contain between 0 and 20 items.");
        }
Esempio n. 3
0
        public void DetectEntities()
        {
            // Get the public timeline
            var timelineResult = TwitterTimeline.PublicTimeline();

            Assert.IsNotNull(timelineResult, "timelineResult is null");
            Assert.IsNotNull(timelineResult.ResponseObject, timelineResult.ErrorMessage);
            Assert.AreNotEqual(0, timelineResult.ResponseObject.Count, timelineResult.ErrorMessage);

            // Get the first tweet with entities
            TwitterStatus tweet = timelineResult.ResponseObject.Where(x => x.Entities != null && x.Entities.OfType <TwitterMentionEntity>().Count() > 0).First();

            // Make sure that we got the tweet successfully
            Assert.IsNotNull(tweet);

            // Get the hashtags
            //var hashTags = from entities in tweet.Entities.OfType<TwitterHashTagEntity>()
            //                select entities;

            // Get the mentions (@screenname within the text)
            var mentions = from entities in tweet.Entities.OfType <TwitterMentionEntity>()
                           select entities;

            // Get urls
            //var urls = from entities in tweet.Entities.OfType<TwitterUrlEntity>()
            //            select entities;

            // Get the tweet text to be modified
            string modifiedTweetText = tweet.Text;

            // Loop through the mentions from the back of the text to the beginning (to retain the index)
            foreach (TwitterMentionEntity mention in mentions.OrderBy(m => m.StartIndex).Reverse())
            {
                string linkText = string.Format("<a href=\"http://twitter.com/{0}\">@{0}</a>", mention.ScreenName);

                modifiedTweetText = string.Concat(
                    modifiedTweetText.Substring(0, mention.StartIndex),
                    linkText,
                    modifiedTweetText.Substring(mention.EndIndex));
            }
        }
Esempio n. 4
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());
            }
        }
Esempio n. 5
0
 public TwitterStatusCollection GetPublicTimeline()
 {
     return(TwitterTimeline.PublicTimeline(privOAuth.GetOAuthToken()).ResponseObject);
 }