Exemplo n.º 1
0
        protected void Load(TwitterResource resource)
        {
            var service = new TwitterService(SensitiveData.ConsumerToken, SensitiveData.ConsumerSecret, resource.User.Key, resource.User.Secret);

            switch (resource.Type)
            {
                case ResourceType.Home:
                    service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions { Count = 1, IncludeEntities = true }, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Mentions:
                    service.ListTweetsMentioningMe(new ListTweetsMentioningMeOptions { Count = 1, IncludeEntities = true }, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Messages:
                    service.ListDirectMessagesReceived(new ListDirectMessagesReceivedOptions { Count = 1 }, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Favorites:
                    service.ListFavoriteTweets(new ListFavoriteTweetsOptions { Count = 1 }, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.List:
                    service.ListTweetsOnList(new ListTweetsOnListOptions
                    {
                        IncludeRts = false,
                        Count = 1,
                        OwnerScreenName = resource.Data.Substring(1, resource.Data.IndexOf('/') - 1),
                        Slug = resource.Data.Substring(resource.Data.IndexOf('/') + 1)
                    }, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Search:
                    service.Search(new SearchOptions { Count = 1, IncludeEntities = true, Q = resource.Data }, (status, response) => ReceiveTweetable(status.Statuses.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Tweets:
                    service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 1, ScreenName = resource.Data, IncludeRts = true }, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
            }
        }
Exemplo n.º 2
0
        private void appbar_button1_Click(object sender, EventArgs e)
        {
            listdata.Visibility = Visibility.Collapsed;
            listdata2.Visibility = Visibility.Collapsed;
            listdata3.Visibility = Visibility.Collapsed;
            listdata4.Visibility = Visibility.Collapsed;
            loadtext.Visibility = Visibility.Visible;
            pgbar.Visibility = Visibility.Visible;
            var item = (PivotItem)title.SelectedItem;
            string header = (string)item.Header;
            service = new TwitterService("g8F2KdKH40gGp9BXemw13Q", "OyFRFsI05agcJtURtLv8lpYbYRwZAIL5gr5xQNPW0Q");
            service.AuthenticateWith((string)settings["twitter_token"], (string)settings["twitter_tokensecret"]);
            if (header == "recent")
            {
                service.ListTweetsOnFriendsTimeline(0, 40,
                (tweets, response) =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        DateTime ti = DateTime.Now;
                        DateTime now = ti.ToUniversalTime();

                        lists = new List<Tweet>();
                        foreach (var tweet in tweets)
                        {
                            Tweet tv = new Tweet();
                            TimeSpan tsp = now - tweet.CreatedDate;
                            tv.id = tweet.Id;
                            tv.name = tweet.User.ScreenName;
                            tv.thumb_img = tweet.User.ProfileImageUrl;
                            tv.text = tweet.Text + "\n";

                            if (tsp.Days > 0)
                                tv.time = tsp.Days + "일 전";
                            else if (tsp.Hours > 0)
                                tv.time = tsp.Hours + "시간 전";
                            else
                                tv.time = tsp.Minutes + "분 전";

                            lists.Add(tv);
                        }
                        Dispatcher.BeginInvoke(delegate()
                        {
                            if (lists.Count > 0)
                            {
                                loadtext.Visibility = Visibility.Collapsed;
                                pgbar.Visibility = Visibility.Collapsed;
                                listdata.ItemsSource = lists;
                                listdata.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                pgbar.Visibility = Visibility.Collapsed;
                                loadtext.Text = "No items";
                            }

                        });
                    }
                });
            }
            else if (header == "replies")
            {
                service.ListTweetsMentioningMe(0, 40,
                (tweets, response) =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        DateTime ti = DateTime.Now;
                        DateTime now = ti.ToUniversalTime();

                        lists = new List<Tweet>();
                        foreach (var tweet in tweets)
                        {
                            Tweet tv = new Tweet();
                            TimeSpan tsp = now - tweet.CreatedDate;
                            tv.id = tweet.Id;
                            tv.name = tweet.User.ScreenName;
                            tv.thumb_img = tweet.User.ProfileImageUrl;
                            tv.text = tweet.Text + "\n";

                            if (tsp.Days > 0)
                                tv.time = tsp.Days + "일 전";
                            else if (tsp.Hours > 0)
                                tv.time = tsp.Hours + "시간 전";
                            else
                                tv.time = tsp.Minutes + "분 전";
                            lists.Add(tv);
                        }
                        Dispatcher.BeginInvoke(delegate()
                        {
                            if (lists.Count > 0)
                            {
                                loadtext.Visibility = Visibility.Collapsed;
                                pgbar.Visibility = Visibility.Collapsed;
                                listdata2.ItemsSource = lists;
                                listdata2.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                pgbar.Visibility = Visibility.Collapsed;
                                loadtext.Text = "No items";
                            }

                        });
                    }
                });
            }
            else if (header == "messages")
            {
                service.ListDirectMessagesReceived(40,
                (tweets, response) =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        DateTime ti = DateTime.Now;
                        DateTime now = ti.ToUniversalTime();

                        lists = new List<Tweet>();
                        foreach (var tweet in tweets)
                        {
                            Tweet tv = new Tweet();
                            TimeSpan tsp = now - tweet.CreatedDate;
                            tv.id = tweet.Id;
                            tv.name = tweet.Sender.ScreenName;
                            tv.thumb_img = tweet.Sender.ProfileImageUrl;
                            tv.text = tweet.Text + "\n";
                            if (tsp.Days > 0)
                                tv.time = tsp.Days + "일 전";
                            else if (tsp.Hours > 0)
                                tv.time = tsp.Hours + "시간 전";
                            else
                                tv.time = tsp.Minutes + "분 전";
                            lists.Add(tv);
                        }
                        Dispatcher.BeginInvoke(delegate()
                        {
                            if (lists.Count > 0)
                            {
                                loadtext.Visibility = Visibility.Collapsed;
                                pgbar.Visibility = Visibility.Collapsed;
                                listdata3.ItemsSource = lists;
                                listdata3.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                pgbar.Visibility = Visibility.Collapsed;
                                loadtext.Text = "No items";
                            }

                        });
                    }
                });
            }
            else if (header == "my")
            {
                service.ListTweetsOnUserTimeline(0, 40,
                (tweets, response) =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        DateTime ti = DateTime.Now;
                        DateTime now = ti.ToUniversalTime();

                        lists = new List<Tweet>();
                        foreach (var tweet in tweets)
                        {
                            Tweet tv = new Tweet();
                            TimeSpan tsp = now - tweet.CreatedDate;
                            tv.id = tweet.Id;
                            tv.name = tweet.User.ScreenName;
                            tv.thumb_img = tweet.User.ProfileImageUrl;
                            tv.text = tweet.Text + "\n";

                            if (tsp.Days > 0)
                                tv.time = tsp.Days + "일 전";
                            else if (tsp.Hours > 0)
                                tv.time = tsp.Hours + "시간 전";
                            else
                                tv.time = tsp.Minutes + "분 전";
                            lists.Add(tv);
                        }
                        Dispatcher.BeginInvoke(delegate()
                        {
                            if (lists.Count > 0)
                            {
                                loadtext.Visibility = Visibility.Collapsed;
                                pgbar.Visibility = Visibility.Collapsed;
                                listdata4.ItemsSource = lists;
                                listdata4.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                pgbar.Visibility = Visibility.Collapsed;
                                loadtext.Text = "No items";
                            }

                        });
                    }
                });
            }
        }
        public IEnumerable<ChannelMessageHeader> GetDirectMessages()
        {
            var service = new TwitterService(ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);
            var result = service.ListDirectMessagesReceived().Union(service.ListDirectMessagesSent());

            foreach (var dm in result)
            {
                yield return new ChannelMessageHeader
                    {
                        MessageIdentifier = dm.Id.ToString(),
                        MessageNumber = dm.Id.ToString(),
                        Context = String.Format("DM from {0}", dm.Sender.Name),
                        From = new SourceAddress(dm.Sender.Id.ToString(), dm.Sender.Name),
                        Body = dm.TextAsHtml,
                        DateReceived = dm.CreatedDate.ToLocalTime()
                    };

            }
        }
Exemplo n.º 4
0
        protected void Load(TwitterResource resource)
        {
            var service = new TwitterService(SensitiveData.ConsumerToken, SensitiveData.ConsumerSecret, resource.User.Key, resource.User.Secret);

            switch (resource.Type)
            {
                case ResourceType.Home:
                    service.ListTweetsOnHomeTimeline(1, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Mentions:
                    service.ListTweetsMentioningMe(1, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Messages:
                    service.ListDirectMessagesReceived(1, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Favorites:
                    service.ListFavoriteTweets((status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.List:
                    service.ListTweetsOnList(resource.Data.Substring(1, resource.Data.IndexOf('/') - 1),
                            resource.Data.Substring(resource.Data.IndexOf('/') + 1), 1, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Search:
                    service.Search(resource.Data, 1, 20, (status, response) => ReceiveTweetable(status.Statuses.Cast<ITweetable>(), response, resource));
                    break;
                case ResourceType.Tweets:
                    service.ListTweetsOnSpecifiedUserTimeline(resource.Data, 1, true, (status, response) => ReceiveTweetable(status.Cast<ITweetable>(), response, resource));
                    break;
            }
        }