private static void Main(string[] args) { ConsoleOutput.PrintMessage("Welcome to BoxKite.Twitter Console (App Auth Tests)"); ConsoleOutput.PrintMessage("(control-c ends)"); System.Console.CancelKeyPress += cancelStreamHandler; twitterConnection = new TwitterConnection("3izxqWiej34yTlofisw", "uncicYQtDx5SoWth1I9xcn5vrpczUct1Oz9ydwTY4"); twitterConnection.StartSearchStreaming("v8sc"); twitterConnection.SearchTimeLine.Subscribe(t => ConsoleOutput.PrintTweet(t)); while (true) { Thread.Sleep(TimeSpan.FromSeconds(0.5)); } }
private static void Main(string[] args) { ConsoleOutput.PrintMessage("Welcome to BoxKite.Twitter Console"); ConsoleOutput.PrintMessage("(control-c ends)"); System.Console.CancelKeyPress += cancelStreamHandler; var twittercredentials = ManageTwitterCredentials.GetTwitterCredentialsFromFile(); if (twittercredentials == null) { // there are no Credentials on file, so create a new set // first, get the Twitter Client (also known as Consumer) Key and Secret from my service var twitterClientKeys = ClientKeyManager.GetTwitterClientKeys().Result; // make a new connection twitterConnection = new TwitterConnection(twitterClientKeys.Item1, twitterClientKeys.Item2); // PIN based authentication var oauth = twitterConnection.BeginUserAuthentication().Result; // if the response is null, something is wrong with the initial request to OAuth if (!string.IsNullOrWhiteSpace(oauth)) { ConsoleOutput.PrintMessage("Pin: "); var pin = System.Console.ReadLine(); twittercredentials = twitterConnection.CompleteUserAuthentication(pin, oauth).Result; ManageTwitterCredentials.SaveTwitterCredentialsToFile(twittercredentials); } else { ConsoleOutput.PrintError("Cannot OAuth with Twitter"); } } if (twittercredentials != null) { twitterConnection = new TwitterConnection(twittercredentials); twitterConnection.StartUserStreaming(); ConsoleOutput.PrintMessage(twitterConnection.TwitterCredentials.ScreenName + " is authorised to use BoxKite.Twitter."); var usersession = twitterConnection.UserSession; var userstream = twitterConnection.UserStream; var applicationsession = twitterConnection.ApplicationSession; var searchstream = twitterConnection.SearchStream; // userstream.Tweets.Subscribe( t => ConsoleOutput.PrintTweet(t)); //userstream.Events.Subscribe(e => ConsoleOutput.PrintEvent(e, ConsoleColor.Yellow)); //userstream.DirectMessages.Subscribe(C:\Users\nhodge\Documents\GitHub\BoxKite.Twitter\src\BoxKite.Twitter\SearchStream.cs // d => ConsoleOutput.PrintDirect(d, ConsoleColor.Magenta, ConsoleColor.Black)); //userstream.Start(); //while (userstream.IsActive) //{ // Thread.Sleep(TimeSpan.FromSeconds(0.5)); //} /*var x = session.SendTweet("d realnickhodge testing & ampersands"); * * if (x.IsFaulted) * { * ConsoleOutput.PrintMessage("bugger"); * } * */ //var locations = new List<string> { "150.700493", "-34.081953", "151.284828", "-33.593316" }; // var locations = new List<string> { "-180", "-90", "180", "90" }; // var track = new List<string> { "mh370" }; twitterConnection.TimeLine.Subscribe(t => { ConsoleOutput.PrintTweet(t, ConsoleColor.Green); }); twitterConnection.Mentions.Subscribe( t => ConsoleOutput.PrintTweet(t, ConsoleColor.White, ConsoleColor.DarkGray)); //twitterConnection.SearchTimeLine.Subscribe(t => { ConsoleOutput.PrintTweet(t, ConsoleColor.Cyan); }); //twitterConnection.StartSearchStreaming("angeles"); while (true) { Thread.Sleep(TimeSpan.FromSeconds(0.5)); } /* * twitterConnection.StartSearch("mh370"); * var xx = session.GetUserProfile(screen_name:"nickhodgemsft").Result; * * if (xx.twitterFaulted) * { * PrintTwitterErrors(xx.twitterControlMessage); * } * else * { * ConsoleOutput.PrintMessage(xx.ToString()); * } * * * * var fileName = "sampleimage\\boxkite1500x500.png"; * * if (File.Exists(fileName)) * { * // var newImage = File.ReadAllBytes(fileName); * * var sr = FilesHelper.FromFile(fileName); * * // var x = session.SendTweetWithImage("Testing Image Upload. You can Ignore", Path.GetFileName(fileName),newImage).Result; * * using (var fs = new FileStream(sr, FileMode.Open, FileAccess.Read)) * { * * var x = session.ChangeProfileBanner("sampleimage\\boxkite1500x500.png", fs).Result; * * // var x = session.SendTweetWithImage("Maggies Rules", "maggie.jpg", fs).Result; * * if (x.twitterFaulted) * { * PrintTwitterErrors(x.twitterControlMessage); * } * else * { * ConsoleOutput.PrintMessage("OK"); * } * * } * * } */ /* * mainTwitterAccount.TimeLine.Subscribe(t => ConsoleOutput.PrintTweet(t)); * mainTwitterAccount.Mentions.Subscribe( * t => ConsoleOutput.PrintTweet(t, ConsoleColor.White, ConsoleColor.DarkGray)); * * while (true) * { * Thread.Sleep(TimeSpan.FromSeconds(0.5)); * } * * Console.ConsoleOutput.PrintMessage("Event stream has stoppped."); * * var locations = new List<string> { "-34.081953", "150.700493", "-33.593316", "151.284828" }; * searchstream = session.StartSearchStream(locations: locations); * searchstream = session.StartSearchStream(track: "hazel"); * searchstream.FoundTweets.Subscribe(t => ConsoleOutput.PrintTweet(t, ConsoleColor.Green)); * searchstream.Start(); * * while (searchstream.IsActive) * { * Thread.Sleep(TimeSpan.FromMinutes(1)); * var sr = new StreamSearchRequest(); * sr.tracks.Add("xbox"); * searchstream.SearchRequests.Publish(sr); * } * */ /* * var x = session.GetMentions(count:100).Result; * * foreach (var tweet in x) * { * ConsoleOutputPrintTweet(tweet); * } * * * session.GetFavourites(count: 10) * .Subscribe(t => ConsoleOutputPrintTweet(t, ConsoleColor.White, ConsoleColor.Black)); */ } ConsoleOutput.PrintMessage("All Finished"); System.Console.ReadLine(); }
public async Task <bool> DoCombosTest(IUserSession session, List <int> testSeq) { var successStatus = true; var trendToFollow = ""; try { // 1 if (testSeq.Contains(1)) { //-33.884097,151.134796 ConsoleOutput.PrintMessage("11.1 Combo\\GetTrendsByLocation then Searchstream for 2 minutes", ConsoleColor.Gray); var combo1 = await session.GetTrendsByLocation(latitude : -33.884097, longitude : 151.134796); if (combo1.OK) { trendToFollow = combo1[0].Name; // grab the first foreach (var trnd in combo1) { ConsoleOutput.PrintMessage( String.Format("Trend Test: {0}", trnd.Name)); } } else { successStatus = false; throw new Exception("cannot trends"); } var searchstream = session.StartSearchStream(track: trendToFollow); searchstream.FoundTweets.Subscribe(t => ConsoleOutput.PrintTweet(t)); searchstream.Start(); Thread.Sleep(TimeSpan.FromMinutes(2)); searchstream.CancelStream.Cancel(); searchstream.Stop(); } // 2 if (testSeq.Contains(2)) { ConsoleOutput.PrintMessage("11.2 Combo\\GetFriendshipRequestsOutgoing, then hydrate User Details", ConsoleColor.Gray); long nextcursor = -1; var ff5ListCount = 0; var userids2 = new List <long>(); do { var ff2List = await session.GetFriendshipRequestsOutgoing(cursor : nextcursor); if (ff2List.twitterFaulted) { successStatus = false; break; } ; nextcursor = ff2List.next_cursor; ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}", ff2List.previous_cursor, ff2List.next_cursor)); foreach (var l in ff2List.UserIDs) { userids2.Add(l); ff5ListCount++; ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l)); } } while (nextcursor != 0); ConsoleOutput.PrintMessage(String.Format("Total Outstanding Outgoing Friend Requests Count: {0}", ff5ListCount)); if (userids2.Any()) { var userlist2 = await session.GetUsersDetailsFull(userIds : userids2); if (userlist2.OK) { foreach (var requsers in userlist2) { ConsoleOutput.PrintMessage( String.Format("UserID: {0} // ScreenName: {1}", requsers.UserId, requsers.ScreenName)); } } else { successStatus = false; } } } // 3 if (testSeq.Contains(3)) { ConsoleOutput.PrintMessage("11.3 Combo\\GetFriendshipRequestsIncoming, then hydrate User Details", ConsoleColor.Gray); long nextcursor = -1; var ff5ListCount = 0; var userids3 = new List <long>(); do { var ff3List = await session.GetFriendshipRequestsIncoming(cursor : nextcursor); if (ff3List.twitterFaulted) { successStatus = false; break; } ; nextcursor = ff3List.next_cursor; ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}", ff3List.previous_cursor, ff3List.next_cursor)); foreach (var l in ff3List.UserIDs) { userids3.Add(l); ff5ListCount++; ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l)); } } while (nextcursor != 0); ConsoleOutput.PrintMessage(String.Format("Total Outstanding Incoming Friend Requests Count: {0}", ff5ListCount)); if (userids3.Any()) { var userlist3 = await session.GetUsersDetailsFull(userIds : userids3); if (userlist3.OK) { foreach (var requsers in userlist3) { ConsoleOutput.PrintMessage( String.Format("UserID: {0} // ScreenName: {1}", requsers.UserId, requsers.ScreenName)); } } else { successStatus = false; } } } } catch (Exception e) { ConsoleOutput.PrintError(e.ToString()); return(false); } return(successStatus); }