Ejemplo 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;
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            string tConsumerKey = "";
            string tConsumerSecret = "";
            string tAccessToken = "";
            string tAccessSecret = "";

            try
            {
                tConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"];
                tConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"];
                tAccessToken = ConfigurationManager.AppSettings["TwitterAccessToken"];
                tAccessSecret = ConfigurationManager.AppSettings["TwitterAccessSecret"];
            }
            catch (Exception)
            {
                throw new System.ArgumentException("Error with Twitter keys", "twitter");
            }

            //build twitter connection
            var twitService = new TweetSharp.TwitterService(tConsumerKey, tConsumerSecret, tAccessToken, tAccessSecret);

            //build options to check for mentions
            var mentionsOptions = new TweetSharp.ListTweetsMentioningMeOptions();
            mentionsOptions.Count = 20;
            mentionsOptions.SinceId = 300328033800306680;

            //get the mentions
            IEnumerable<TwitterStatus> mentions = twitService.ListTweetsMentioningMe(mentionsOptions);

            List<TwitterStatus> listOfStuff = mentions.ToList();
            listOfStuff.ForEach(
                x =>
                {
                    Console.WriteLine("Now gathering info about tweet #{0}.", x.Id);
                    Console.WriteLine("It is in response to tweet #{0}.", x.InReplyToStatusId);

                    var thatTweet = twitService.GetTweet(new GetTweetOptions { Id = (long)x.InReplyToStatusId });

                    Console.WriteLine("That tweet's text was {0}", thatTweet.Text);
                    Console.WriteLine("More importantly, heres the url it was referencing {0}", thatTweet.Entities.Urls[0].ExpandedValue);

                    string moveString = "not found";

                    if (x.Text.Contains("*"))
                    {
                        int startIndex = x.Text.IndexOf("*");
                        int endIndex = x.Text.LastIndexOf("*");
                        moveString = x.Text.Substring(startIndex, endIndex - startIndex + 1);
                    }
                    Console.WriteLine("The move attached to this tweet was {0}.", moveString);
                }
            );
            Console.WriteLine("End of new API stuff");
        }
Ejemplo n.º 4
0
        public void CanListMentions()
        {
            var service = new TwitterService(consumerKey, consumerSecret);
            service.AuthenticateWith(accessToken, accessTokenSecret);

            var mentions = service.ListTweetsMentioningMe();

            Console.WriteLine("Number of mentions: {0}", mentions.Count());

            foreach(var mention in mentions)
            {
                Console.WriteLine("{0}", mention.RawSource);
            }
        }
Ejemplo n.º 5
0
        private static void StartServer()
        {
            var serv = new TwitterService(AuthVars.ConsumerKey, AuthVars.ConsumerSecret);
            serv.AuthenticateWith(AuthVars.TokenPublic, AuthVars.TokenSecret);
            string song = null;
            string artist = null;
            string album = null;
            var iT = new iTunesApp();
            var currPl = (iT.LibrarySource.Playlists.ItemByName["C# Interface"] ??
                         iT.CreatePlaylist("C# Interface")) as IITUserPlaylist;
            if (currPl == null)
            {
                Console.WriteLine("Could not find or create playlist. Exiting");
                throw new Exception("Could not find or create playlist. Exiting");
            }

            TwitterStatus tw = null;
            while (true)
            {
                List<TwitterStatus> tweets = tw != null ? new List<TwitterStatus>(serv.ListTweetsMentioningMe(new ListTweetsMentioningMeOptions { SinceId = tw.Id })) : new List<TwitterStatus>(serv.ListTweetsMentioningMe(new ListTweetsMentioningMeOptions()));
                tweets = tweets.Where(s => s.Text.Substring(s.Text.IndexOf(" ", StringComparison.Ordinal) + 1).Replace("&amp;", "&").StartsWith("DJ:")).ToList();
                if (tweets.Count > 0)
                {
                    tweets.Reverse();
                    foreach (var tweet in tweets)
                    {
                        tw = tweet;
                        IITTrack t = null;
                        var tweetText = tweet.Text;
                        tweetText = tweetText.Substring(tweetText.IndexOf(" ", StringComparison.Ordinal) + 1).Replace("&amp;", "&");
                        if (tweetText.Contains("|"))
                        {
                            tweetText = tweetText.Substring(tweetText.IndexOf("DJ:", StringComparison.Ordinal) + "DJ:".Length);
                            var songParts = tweetText.Split('|');
                            foreach (var part in songParts)
                            {
                                Console.Write(part);
                                Console.Write("||");
                            }
                            Console.WriteLine();
                            song = songParts[1].Trim().ToUpper();
                            artist = songParts[0].Trim().ToUpper();
                            album = songParts.Length == 3 ? songParts[2].Trim().ToUpper() : "";
                            string searchText = song + " " + artist + " " + album;
                            var s = iT.LibraryPlaylist.Search(searchText, ITPlaylistSearchField.ITPlaylistSearchFieldVisible);
                            t = s.Cast<IITTrack>().First(t2 => t2.Name.ToUpper() == song && t2.Artist.ToUpper() == artist && (t2.Album.ToUpper() == album || album == ""));
                            Console.WriteLine(t.Artist + "||" + t.Album + "||" + t.Name);
                        }
                        else if (tweetText.ToUpper().Contains("SHUFFLE") || tweetText.ToUpper().Contains("RANDOM"))
                        {
                            var rnd = new Random(10);
                            var libSize = iT.LibraryPlaylist.Tracks.Count;
                            var idx = rnd.Next(libSize);
                            t = iT.LibraryPlaylist.Tracks.ItemByPlayOrder[idx];
                            song = t.Name;
                            artist = t.Artist;
                            album = t.Album;
                        }
                        var tInPl = currPl.Tracks;
                        if (t != null && (tInPl.ItemByName[song] == null || tInPl.ItemByName[artist] == null))
                        {
                            if (album != "")
                            {
                                if (tInPl.ItemByName[album] == null)
                                    currPl.AddTrack(t);
                            }
                            else
                            {
                                currPl.AddTrack(t);
                            }
                        }
                        Console.WriteLine("\n**********************");
                    }
                    Console.WriteLine("Waiting 30 seconds before checking again");
                }
                else
                {
                    Console.WriteLine("No tweets found, either new or old, waiting 30sec");
                }
                System.Threading.Thread.Sleep(30000);
            }
        }
Ejemplo n.º 6
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";
                            }

                        });
                    }
                });
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            //OAuthInfo myOAuth =  new OAuthInfo();
            //myOAuth.ConsumerKey = "8TmvHbMNWugTpk9lIpbdQ";
            //myOAuth.ConsumerSecret = "AmDxGd29eSUjERuyy20p5bZaFrpLfgYTCP5Qi1K0crw";
            //myOAuth.AccessToken = "21985278-14mhmDF5238JlIeA68ak2MudVhXuHsmkhsNoMTDsp";
            //myOAuth.AccessSecret = "MTpjzzkibGWM6KU8Za2B4WJUieskPEjrAVxBhY2oQ";

            //TinyTwitter TT = new TinyTwitter(new OAuthInfo());

            //IEnumerable<Tweet> mytimneline = TT.GetHomeTimeline(null, 2);
            //Console.ReadKey();

            var service = new TwitterService("tedRo766zL7mr7TKZkOugA", "WREOp5SZ71EtLCt3T4RboUv1IrkUpPkCpcBxkAGk8");
            //var service = new TwitterService("bWDpCLO2mIByqMYoaRh2Cg", "X4veUKVWhB09wipWhVpaVhXvLDHqzIjnOLOGXxiY8Y");
            service.AuthenticateWith("21985278-dud1wSertHCQYTUK5ta5AA0ciqWB31ZsT8Dt8DJg", "yPDp2TTOOhQj6XDxX7P5TxmNtHZcQ6sJumth8DVzRk");
            //service.AuthenticateWith("25963011-QuJkeaEcXqB92bhMxoIJHKBLFHP1rPZysu6K68IqZ", "pY0TXRW8aIUSDfSUpJAzsQ2s2Oay2A0HBdiaK1Z8");
            //var tweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions());
            //var tweets = service.ListRetweetsOfMyTweets(new ListRetweetsOfMyTweetsOptions());
            //var tweets = service.ListFavoriteTweets(new ListFavoriteTweetsOptions());
            var tweets = service.ListTweetsMentioningMe(new ListTweetsMentioningMeOptions());

            //var MyTweetOptions = new SendTweetOptions();
            //MyTweetOptions.Status = "Hello World";

            //service.SendTweet(MyTweetOptions);

            var myFriendLists = service.GetIncomingFriendRequests(new GetIncomingFriendRequestsOptions());

            foreach (var FriendLists in myFriendLists)
            {
                var MyFriendOptions = new GetUserProfileForOptions();
                MyFriendOptions.UserId = FriendLists;

                var MyFriend = service.GetUserProfileFor(MyFriendOptions);

                Console.WriteLine("{0} says", FriendLists.ToString());
                Console.ReadKey();

            }

            //foreach (var tweet in tweets)
            //{
            //    Console.WriteLine("{0} says '{1}'", tweet.Id, tweet.Text);
            //    Console.ReadKey();

            //}

            //using TweetSharp;

            // Pass your credentials to the service
             //           TwitterService service = new TwitterService("bWDpCLO2mIByqMYoaRh2Cg", "X4veUKVWhB09wipWhVpaVhXvLDHqzIjnOLOGXxiY8Y");

            // Step 1 - Retrieve an OAuth Request Token
            //OAuthRequestToken requestToken = service.GetRequestToken();

            // Step 2 - Redirect to the OAuth Authorization URL
            //Uri uri = service.GetAuthorizationUri(requestToken);
            //Process.Start(uri.ToString());

            // Step 3 - Exchange the Request Token for an Access Token
            //string verifier = Console.ReadLine(); // <-- This is input into your application by your user
            //OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);

            // Step 4 - User authenticates using the Access Token
            //service.AuthenticateWith(access.Token, access.TokenSecret);
            //IEnumerable<TwitterStatus> mentions = service.ListTweetsMentioningMe);

            //var tweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions());
            //var myRetweetsOption = new ListRetweetsOfMyTweetsOptions();
            //myRetweetsOption.SinceId = 313064862320300032;
            //tweets = service.ListRetweetsOfMyTweets(myRetweetsOption);
            //
            //foreach (var tweet in tweets)
            //{
            //Console.WriteLine("{0} says '{1}' id:{3} ", tweet.User.ScreenName, tweet.Text, tweet.Id);
              //  Console.WriteLine("{0} says '{1}' ", tweet.Id, tweet.Text);
            //Console.ReadKey();

            //}
            //Console.ReadKey();
        }
Ejemplo n.º 8
0
        private static TwitterStatus GetNextResponseDue()
        {
            long lastTweetId = Helper.GetLastKnownTweetId();

            TwitterService service =
                new TwitterService(Helper.GetPublicKey(), Helper.GetSecretKey());

            service.AuthenticateWith(Helper.GetPublicToken(), Helper.GetSecretToken());

            ListTweetsMentioningMeOptions options = new ListTweetsMentioningMeOptions()
            {
                SinceId = lastTweetId
            };

            IEnumerable<TwitterStatus> myTweets =
                service.ListTweetsMentioningMe(options);

            return myTweets.OrderBy(o=>o.Id).FirstOrDefault();
        }
Ejemplo n.º 9
0
        public IEnumerable<ChannelStatusUpdate> GetMentions(int pageSize)
        {
            var service = new TwitterService(ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);
            var result = service.ListTweetsMentioningMe();

            foreach (var tweet in result)
            {
                yield return new ChannelStatusUpdate
                    {
                        ChannelStatusKey = tweet.Id.ToString(),
                        Status = tweet.Text,
                        From = new SourceAddress(
                            tweet.User.ScreenName,
                            tweet.User.Name,
                            tweet.User.ProfileImageUrl.Replace("_normal.jpg", "_mini.jpg")),
                        DatePosted = tweet.CreatedDate
                    };
            }
        }
Ejemplo n.º 10
0
        private void start_update()
        {
            tr_chk = false;
            fr_chk = false;
            mr_chk = false;
            lists = new List<NotifiView>();
            if (t_chk == true)
            {
                TwitterService service = new TwitterService("g8F2KdKH40gGp9BXemw13Q", "OyFRFsI05agcJtURtLv8lpYbYRwZAIL5gr5xQNPW0Q");
                service.AuthenticateWith((string)settings["twitter_token"], (string)settings["twitter_tokensecret"]);
                service.ListTweetsMentioningMe(0, 10,
                        (tweets, response) =>
                        {
                            if (response.StatusCode == HttpStatusCode.OK)
                            {
                                tr_chk = true;
                                foreach (var tweet in tweets)
                                {
                                    NotifiView list = new NotifiView();
                                    list.name = tweet.Author.ScreenName;
                                    list.id = tweet.Id.ToString();
                                    list.type = "twitter.png";
                                    list.thumb_img = tweet.User.ProfileImageUrl;
                                    list.text = tweet.Text;
                                    list.dtime = tweet.CreatedDate.ToLocalTime();
                                    Dispatcher.BeginInvoke(delegate()
                                    {
                                        lists.Add(list);
                                    });
                                }
                                Dispatcher.BeginInvoke(delegate()
                                {
                                    check_end();
                                });
                            }

                        });

            }

            if (f_chk == true)
            {
                string url = String.Format("https://api.facebook.com/method/notifications.getList?access_token={0}&format=json", (string)settings["facebook_token"]);
                WebClient wc = new WebClient();
                wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_openHandler_facebook);
                wc.DownloadStringAsync(new Uri(url), UriKind.Absolute);
            }

            if (m_chk == true)
            {
                string url = String.Format("http://me2day.net/api/track_comments/{0}.xml?akey=aed420d038f9b1a7fe3b5c0d94df22f5&scope=to_me&count=10", (string)settings["me2day_userid"]);
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
                webRequest.Method = "POST";

                string auth_key = String.Format("full_auth_token {0}", settings["me2day_token"]);
                webRequest.Credentials = new NetworkCredential((string)settings["me2day_userid"], auth_key);
                IAsyncResult token = webRequest.BeginGetResponse(new AsyncCallback(wc_openHandler_me2day), webRequest);
            }
        }
Ejemplo n.º 11
0
        private IEnumerable<TwitterStatus> GetMentions()
        {
            var service = new TwitterService(ClientInfo);
            service.AuthenticateWith(Token, TokenSecret);

            LastResponse = service.Response;
            return service.ListTweetsMentioningMe();
        }
Ejemplo n.º 12
0
        public AskModule(IDocumentSession documentSession, IHubContext hubContext)
        {
            Get["/ask"] = _ =>
            {
                try
                {
                    // RavenDb
                    var storedQuestions = documentSession.Query<Question>().OrderByDescending(x => x.DateAsked).ToList();

                    // Twitter
                    var twitterService = new TwitterService(TwitterConsumerKey, TwitterConsumerSecret);
                    twitterService.AuthenticateWith(TwitterAccessToken, TwitterAccessTokenSecret);

                    var twitterOptions = new ListTweetsMentioningMeOptions();
                    if (storedQuestions.Any())
                    {
                        var sinceId = storedQuestions.First().MessageId;
                        twitterOptions.SinceId = sinceId;
                    }

                    var tweets = twitterService.ListTweetsMentioningMe(twitterOptions).ToList();
                    if (!tweets.Any()) return null;

                    var nextQuestion = tweets.First(t => !string.IsNullOrEmpty(t.Text) && t.Text.Contains("#drsharp"));

                    //var model = this.Bind<AskViewModel>();

                    var pathToAiml = System.Web.HttpContext.Current.Server.MapPath(@"~/aiml");
                    var drSharp = new DoctorSharp(pathToAiml);
                    var answer = drSharp.Ask(nextQuestion.Author.ScreenName, nextQuestion.Text);

                    // Note: tweet working, but not in reply to sender. Also need to add some hashtag to the answer.
                    //twitterService.SendTweet(new SendTweetOptions
                    //{
                    //    DisplayCoordinates = false,
                    //    InReplyToStatusId = nextQuestion.Id,
                    //    Status = answer
                    //});

                    var question = new Question
                    {
                        From = nextQuestion.Author.ScreenName,
                        DateAsked = nextQuestion.CreatedDate,
                        Content = nextQuestion.Text,
                        MessageId = nextQuestion.Id,
                        Answer = answer
                    };

                    documentSession.Store(question);
                    documentSession.SaveChanges();

                    // SignalR
                    hubContext.Clients.All.broadcastAnswer(question.Content, question.Answer, question.From);
                    return null;
                }
                catch (Exception ex)
                {
                    return string.Format("Message: {0}\r\nDetail {1}", ex.Message, ex.StackTrace);
                }

            };
        }