private static async Task MainAsync(string[] args) { const string filename = "credentials.json"; var json = File.ReadAllText(filename); var credentials = JsonConvert.DeserializeObject<TwitterCredentials>(json); var session = new UserSession(credentials, new DesktopPlatformAdaptor()); var user = await session.GetVerifyCredentials(); if (user.OK) { Console.WriteLine(credentials.ScreenName + " is authorised to use BoxKite.Twitter."); var stream = session.StartSearchStream(track: "#yolo"); stream.FoundTweets.Subscribe(tweet => { Console.WriteLine(String.Format("ScreenName: {0}, Tweet: {1}", tweet.User.ScreenName, tweet.Text)); }); stream.Start(); } else { Console.WriteLine("Credentials found in {0} were invalid, please run the Authenticator and copy over the resulting output.", filename); } Thread.Sleep(Timeout.Infinite); }
private static async Task MainAsync(string[] args) { var twitterCredentials = new TwitterCredentials() { ConsumerKey = AppSettings.ApplicationConsumerKey, ConsumerSecret = AppSettings.ApplicationConsumerSecret, }; var twitter = new UserSession(twitterCredentials, new DesktopPlatformAdaptor()); var oathToken = await twitter.StartUserAuthentication(); Console.Write("Please enter the PIN as displayed in the new browser window: "); var pin = Console.ReadLine(); var credentials = await twitter.ConfirmPin(pin, oathToken); if (credentials.Valid) { const string filename = "credentials.json"; string json = JsonConvert.SerializeObject(credentials); File.WriteAllText(filename, json); Console.WriteLine("Credentials were successfully saved to '{0}'", filename); } else { Console.WriteLine("Credentials were invalid."); } Console.ReadLine(); }
/// <summary> /// Second stage of PIN-based Authentication (and Authorisation) confirms the supplied PIN is correct /// for this user, application, session /// </summary> /// <param name="pin">PIN as entered by the user</param> /// <param name="oAuthToken">OAuth token supplied by BeginUserAuthentication</param> /// <returns>TwitterCredentials</returns> public async Task <TwitterCredentials> CompleteUserAuthentication(string pin, string oAuthToken) { var twittercredentials = await UserSession.ConfirmPin(pin, oAuthToken); return(!twittercredentials.Valid ? null : twittercredentials); }
/// <summary> /// XAuthentication is a method of creating a set of Credentials for Twitter based on Username and Password /// Whilst this is in BoxKite.Twitter, it has not been fully tested /// </summary> /// <param name="xauthusername">user supplied Username</param> /// <param name="xauthpassword">user supplied Password</param> /// <returns></returns> public async Task <TwitterCredentials> XAuthentication(string xauthusername, string xauthpassword) { var twittercredentials = await UserSession.XAuthentication(xauthusername, xauthpassword); return(!twittercredentials.Valid ? null : twittercredentials); }
/// <summary> /// First stage of PIN-based Authentication (and Authorisation) /// This will display a web browser, asking the User to log in to Twitter with their account (Authentication) /// and Authorise this client application to access their Twitter Stream /// </summary> /// <returns>OAuth to be used in CompleteUserAuthentication</returns> public async Task <string> BeginUserAuthentication() { return(await UserSession.StartUserAuthentication()); }