Пример #1
0
        public static List <TweetDisplay> GetTweets(string searchCriteria)
        {
            // initialise a Credentials object with the keys supplied by the twitter api registration
            var credentials = CredentialsCreator.GenerateApplicationCredentials(consumerKey, consumerSecret);

            // tell twitter our credentials
            TwitterCredentials.SetCredentials(credentials.AuthorizationKey, credentials.AuthorizationSecret,
                                              credentials.ConsumerKey, credentials.ConsumerSecret);

            // Search the tweets containing the search criteria and create a list to display in the view, only use top 4
            var items = Search.SearchTweets(searchCriteria).OrderByDescending(a => a.CreatedAt).ToList().Take(4);

            // create an empty list
            var results = new List <TweetDisplay>();

            // Make a list of tweet items for using in the view
            foreach (var item in items)
            {
                var td = new TweetDisplay
                {
                    CreatedAt = item.CreatedAt,
                    Author    = item.Creator.Name,
                    Tweet     = item.Text,
                    ImageUrl  = item.Creator.ProfileImageUrl
                };

                results.Add(td);
            }

            return(results);
        }
Пример #2
0
 public void GetVerifierURL(string consumerKey, string consumerSecret)
 {
     if (!loggedIn)
     {
         if (!IsConnectedToInternet())
         {
             FOutputStatus[0] = "Can't authorize as your internet is f****d bro.";
             FLogger.Log(LogType.Debug, "Can't authorize as your internet is f****d bro.");
             ClearOutputPins();
             FOutputStatusBool[0] = false; loggedIn = false;
         }
         else
         {
             try
             {
                 applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(consumerKey, consumerSecret);
                 url              = CredentialsCreator.GetAuthorizationURLForCallback(applicationCredentials, "");
                 FOutputURL[0]    = url;
                 FOutputStatus[0] = "Authorization URL passed, nice one.";
                 FLogger.Log(LogType.Debug, "Authorization URL passed, nice one.");
             }
             catch
             {
                 FOutputStatus[0] = "Bad consumer key or secret, monsieur tete de bite.";
                 FLogger.Log(LogType.Debug, "Bad consumer key or secret, monsieur tete de bite.");
             }
         }
     }
     else
     {
         FOutputStatus[0] = "You're already logged in, you douche, logout first.";
         FLogger.Log(LogType.Debug, "You'RE already logged in, you douche, logout first.");
     }
 }
Пример #3
0
        private void GetCredentials()
        {
            // Check for saved credentials JSON file
            string fileName = "credentials.json";

            if (File.Exists(fileName))
            {
                try
                {
                    Console.WriteLine("Retrieving saved credentials...");
                    StreamReader reader = new StreamReader(fileName);
                    string       json   = reader.ReadToEnd();
                    reader.Close();
                    AuthInfo = JsonConvert.DeserializeObject <AuthInfo>(json);
                }
                catch (Exception)
                {
                    Console.WriteLine("Error deserializing credentials.");
                }
            }
            else
            {
                var    credentials = CredentialsCreator.GenerateApplicationCredentials(Keys.API_KEY, Keys.API_SECRET);
                string url         = CredentialsCreator.GetAuthorizationURL(credentials);
                System.Diagnostics.Process.Start(url); // Open web browser

                Console.WriteLine("Enter PIN:");
                string pin           = Console.ReadLine();
                var    authorization = CredentialsCreator.GetCredentialsFromVerifierCode(pin, credentials);
                AuthInfo = new AuthInfo(Keys.API_KEY, Keys.API_SECRET, authorization.AccessToken, authorization.AccessTokenSecret);

                Console.WriteLine("Would you like to save these credentials so that you don't have to authenticate next time?\nY/N");
                var reply = Console.ReadKey();
                if (reply.Key.ToString() == "Y")
                {
                    string       json   = JsonConvert.SerializeObject(AuthInfo);
                    StreamWriter writer = new StreamWriter(fileName);
                    writer.WriteLine(json);
                    writer.Close();
                }
            }
        }
Пример #4
0
        /*
         * Function that handles the first program load
         */
        private static void showDialog()
        {
            var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(Properties.Resources.api_key,
                                                                                           Properties.Resources.api_key_secret);
            var     url  = CredentialsCreator.GetAuthorizationURL(applicationCredentials);
            PinForm form = new PinForm(url);

            Application.Run(form);
            captcha = form.getCap();
            try
            {
                var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);
                Properties.Settings.Default.access_token        = newCredentials.AccessToken;
                Properties.Settings.Default.access_token_secret = newCredentials.AccessTokenSecret;
                Properties.Settings.Default.Save();
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
                Application.Exit();
            }
        }
Пример #5
0
 // This method shows you how to create Application credentials.
 // This type of credentials do not take a AccessKey or AccessSecret.
 private ITemporaryCredentials CreateApplicationCredentials(string consumerKey, string consumerSecret)
 {
     return(CredentialsCreator.GenerateApplicationCredentials(consumerKey, consumerSecret));
 }