Пример #1
0
        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();
        }
Пример #2
0
 /// <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());
 }