Пример #1
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.");
     }
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var url =
                CredentialsCreator.GetAuthorizationURL(TwitterConnectionInfoSingleton.getInstance().GetAppCredentials());

            TwitterPin.Source = new Uri(url);
        }
Пример #3
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);
        }
Пример #4
0
        public ActionResult ValidateTwitterAuth()
        {
            var verifierCode    = Request.Params.Get("oauth_verifier");
            var authorizationId = Request.Params.Get("authorization_id");

            var userCreds = CredentialsCreator.GetCredentialsFromVerifierCode(verifierCode, authorizationId);
            var user      = Tweetinvi.User.GetLoggedUser(userCreds);

            ViewBag.User = user;

            var homeTimeline = user.GetHomeTimeline();

            List <TweetViewModel> tweetList = new List <TweetViewModel>();

            foreach (var tweet in homeTimeline)
            {
                TweetViewModel tweetView = new TweetViewModel();
                tweetView.Id                  = tweet.Id.ToString();
                tweetView.Author              = tweet.CreatedBy.ToString();
                tweetView.Text                = tweet.Text.ToString();
                tweetView.DatePosted          = tweet.CreatedAt;
                tweetView.UsersFavouriteCount = tweet.FavouriteCount;
                tweetView.RetweetsCount       = tweet.RetweetCount;
                //tweetView.RepliesCount =
                tweetList.Add(tweetView);
            }

            return(View(tweetList));
        }
Пример #5
0
        // We need the user to go on the Twitter Website to authorize our application
        private void GoToTwitterCaptchaPage(ITemporaryCredentials applicationCredentials)
        {
            var url = CredentialsCreator.GetAuthorizationURL(applicationCredentials);

            Console.WriteLine("Please go on {0}, to accept the application and get the captcha.", url);
            Process.Start(url.ToString());
        }
        private async void ValidatePinCode()
        {
            if (!String.IsNullOrEmpty(PinCode))
            {
                var userCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(PinCode, MainPageViewModel.AppCredentials);
                Auth.SetCredentials(userCredentials);

                if (Auth.ApplicationCredentials != null)
                {
                    var loggedUser = User.GetAuthenticatedUser();

                    if (!String.IsNullOrEmpty(loggedUser.ScreenName))
                    {
                        MainPageViewModel.TweetinviData.AccessToken       = loggedUser.Credentials.AccessToken;
                        MainPageViewModel.TweetinviData.AccessTokenSecret = loggedUser.Credentials.AccessTokenSecret;

                        AccountManager ac = new AccountManager();
                        ac.CreateJsonData();
                        await ac.SaveDataToFile();

                        NavigationService.Navigate(typeof(Views.HomeTimelinePage));
                    }
                }
            }
        }
Пример #7
0
        private static IOAuthCredentials CredentialsCreator_CreateFromRedirectedCallbackURL_SingleStep(string consumerKey, string consumerSecret)
        {
            //if (string.IsNullOrEmpty(User.Default.TwitterAccessKey) || string.IsNullOrEmpty(User.Default.TwitterAccessToken))
            //    {
            Func <string, string> retrieveCallbackURL = url =>
            {
                Console.WriteLine("Go on : {0}", url);
                Console.WriteLine("When redirected to your website copy and paste the URL: ");

                // Enter a value like: https://tweeetinvi.codeplex.com?oauth_token={tokenValue}&oauth_verifier={verifierValue}

                var callbackURL = Console.ReadLine();
                return(callbackURL);
            };

            // Here we provide the entire URL where the user has been redirected
            var newCredentials = CredentialsCreator.GetCredentialsFromCallbackURL_UsingRedirectedCallbackURL(retrieveCallbackURL, consumerKey, consumerSecret, "https://tweetinvi.codeplex.com");

            Console.WriteLine("Access Token = {0}", newCredentials.AccessToken);
            Console.WriteLine("Access Token Secret = {0}", newCredentials.AccessTokenSecret);
            User.Default.TwitterAccessKey   = newCredentials.AccessToken;
            User.Default.TwitterAccessToken = newCredentials.AccessTokenSecret;
            User.Default.Save();
            return(newCredentials);

            //}
            return(TwitterCredentials.CreateCredentials(User.Default.TwitterAccessToken, User.Default.TwitterAccessKey, consumerKey, consumerSecret));
        }
Пример #8
0
        public ActionResult TwitterAuth()
        {
            var appCreds    = new ConsumerCredentials(CONSUMER_KEY, CONSUMER_SECRET);
            var redirectURL = "http://" + Request.Url.Authority + "/Home/ValidateTwitterAuth";
            var url         = CredentialsCreator.GetAuthorizationURL(appCreds, redirectURL);

            return(new RedirectResult(url));
        }
Пример #9
0
        public static void GetTwitterAuthorizationUrl()
        {
            _applicationCredentials = new TwitterCredentials(ConfigurationManager.AppSettings["twitterConsumerKey"],
                                                             ConfigurationManager.AppSettings["twitterConsumerSecret"]);
            var url = CredentialsCreator.GetAuthorizationURL(_applicationCredentials);

            System.Diagnostics.Process.Start(url);
        }
Пример #10
0
        public ActionResult ValidateTwitterAuth()
        {
            var verifierCode    = Request.Params.Get("oauth_verifier");
            var authorizationId = Request.Params.Get("authorization_id");

            var userCreds = CredentialsCreator.GetCredentialsFromVerifierCode(verifierCode, authorizationId);
            var user      = Tweetinvi.User.GetLoggedUser(userCreds);

            ViewBag.User = user;

            return(View());
        }
Пример #11
0
 private void Window_btnAuthorizeClicked(object sender, EventArgs e)
 {
     try
     {
         // Make the user go on the URL so that Twitter authenticates him and gives a PIN code
         Process.Start(CredentialsCreator.GetAuthorizationURL(AppCredentials));
     }
     catch (Exception)
     {
         new ErrorDialog("Cannot connect with server");
         Window.Close();
     }
 }
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
        {
            NavigationService.ClearHistory();

            AppCredentials = new TwitterCredentials(TweetinviData.ConsumerKey, TweetinviData.ConsumerSecret);
            var url = CredentialsCreator.GetAuthorizationURL(AppCredentials);

            if (String.IsNullOrEmpty(url))
            {
                NavigationService.Navigate(typeof(Views.MainPage));
            }

            Uri targeturi = new Uri(url);

            NavigationService.Navigate(typeof(Views.LoginPage), targeturi);

            await Task.CompletedTask;
        }
Пример #13
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();
                }
            }
        }
Пример #14
0
        private void Window_btnLoginClicked(object sender, EventArgs e)
        {
            try
            {
                // With tthe pin code it is now possible to get the credentials back from Twitter
                ITwitterCredentials credentials = CredentialsCreator.GetCredentialsFromVerifierCode
                                                      (Window.Pin, AppCredentials);

                if (credentials != null)
                {
                    // Use the user credentials
                    Tweetinvi.Auth.SetCredentials(credentials);
                }

                if (Tweetinvi.User.GetLoggedUser() != null)
                {
                    var mainController = new MainController();
                    mainController.HandleNavigation(null);

                    if (Window.RememberChecked)
                    {
                        // Save user credentials
                        SavedToken.Set(new Token(Tweetinvi.User.GetLoggedUser().Name,
                                                 credentials.AccessToken, credentials.AccessTokenSecret));
                    }

                    Window.Close();
                }
                else
                {
                    Window.ShowError("Incorrect PIN.");
                    AppCredentials.AuthorizationKey    = null;
                    AppCredentials.AuthorizationSecret = null;
                    Window.RepeatAuthorization();
                }
            }
            catch (Exception)
            {
                new ErrorDialog("Cannot login. Check your internet connection and entered PIN-code");
            }
        }
Пример #15
0
 public static async void GenerateCredentials(string captcha)
 {
     if (captcha != null)
     {
         _userCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, _applicationCredentials);
         if (_userCredentials == null)
         {
             await MetroWindow.ShowMessageAsync("TWITTER CAPTCHA", "Wpisałeś błędny kod!");
         }
         else
         {
             Authorize();
             SaveConfiguration();
             await MetroWindow.ShowMessageAsync(_loggedUser.ScreenName, "Zalogowano!");
         }
     }
     else
     {
         await MetroWindow.ShowMessageAsync("TWITTER CAPTCHA", "Nie wpisałeś kodu captcha!");
     }
 }
Пример #16
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();
            }
        }
Пример #17
0
        /// <summary>
        /// Requests an authentication token and redirects the user to Twitter
        /// </summary>
        public ActionResult Oauth()
        {
            ConsumerCredentials appCreds;

            string redirectURL, oauthURL;

            try
            {
                Session[SK.Redirect] = Request.QueryString["redirect_uri"];

                appCreds = new ConsumerCredentials(consumerKey, consumerSecret);

                redirectURL = "http://" + Request.Url.Authority + "/twitter/callback";

                oauthURL = CredentialsCreator.GetAuthorizationURL(appCreds, redirectURL);

                return(new RedirectResult(oauthURL));
            }
            catch (Exception)
            {
                return(new RedirectResult("/twitter/check"));
            }
        }
Пример #18
0
        public async void ConnectPin()
        {
            if (!string.IsNullOrEmpty(_pinInput))
            {
                var userCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(PinInput, TwitterConnectionInfoSingleton.getInstance().GetAppCredentials());

                if (userCredentials != null)
                {
                    Auth.SetCredentials(userCredentials);
                    var account = new Token(userCredentials.AccessToken, userCredentials.AccessTokenSecret);
                    AccountToken.SaveAccountData(account);
                    this.NavigationService.Navigate(typeof(Views.TimeLine));
                }
                else
                {
                    var msgDialogue = new MessageDialog("Pin code invalid", "Connection error");
                    await msgDialogue.ShowAsync();
                }

                return;
            }

            if (File.Exists(ApplicationData.Current.LocalFolder.Path + "\\config.json"))
            {
                var tokens          = AccountToken.ReadTokens();
                var userCredentials =
                    Auth.CreateCredentials(TwitterConnectionInfoSingleton.getInstance().getConsumerKey(), TwitterConnectionInfoSingleton.getInstance().getConsumerSecret(), tokens.token,
                                           tokens.tokenSecret);
                Auth.SetCredentials(userCredentials);
                this.NavigationService.Navigate(typeof(Views.TimeLine));
            }
            else
            {
                var msgDialogue = new MessageDialog("No account registered", "Connection error");
                await msgDialogue.ShowAsync();
            }
        }
Пример #19
0
 public void GetCredentialsAndLogin(string verifierCode)
 {
     if (!IsConnectedToInternet())
     {
         FOutputStatus[0] = "Can't login as your internet is f****d bro.";
         FLogger.Log(LogType.Debug, "Can't login as your internet is f****d bro.");
         ClearOutputPins();
         FOutputStatusBool[0] = false; loggedIn = false;
     }
     else
     {
         try
         {
             newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(verifierCode, applicationCredentials);
             TwitterCredentials.Credentials = newCredentials;
             GetRateLimits("Login failed! Expired or bad verifier code?");
         }
         catch
         {
             FOutputStatus[0] = "Expired or bad verifier code, sac a vin";
             FLogger.Log(LogType.Debug, "Expired or bad verifier code, sac a vin.");
         }
     }
 }
Пример #20
0
        /// <summary>
        /// Saves user credentials in the user session and redirects him
        /// </summary>
        public ActionResult Callback()
        {
            ITwitterCredentials userCreds;

            string verifierCode, authorizationId, redirect_uri;

            try
            {
                verifierCode    = Request.Params.Get("oauth_verifier");
                authorizationId = Request.Params.Get("authorization_id");

                userCreds = CredentialsCreator.GetCredentialsFromVerifierCode(verifierCode, authorizationId);

                Session[SK.User] = userCreds;

                redirect_uri = Session[SK.Redirect].ToString();

                return(Redirect(redirect_uri));
            }
            catch (Exception)
            {
                return(new RedirectResult("/twitter/check"));
            }
        }
Пример #21
0
        // On the Twitter website the user will get a captcha that he will need to enter in the application
        private void GenerateCredentialsAndLogin(string captcha, ITemporaryCredentials applicationCredentials)
        {
            var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);

            // And now the user is logged in!
            TwitterCredentials.SetCredentials(newCredentials);

            var loggedUser = User.GetLoggedUser();

            Console.WriteLine("You are logged as {0}", loggedUser.ScreenName);

            if (loggedUser.ScreenName != "")
            {
                CurrentStatusCount.Text = "Authorised";
                accesskey.Text          = newCredentials.AccessToken;
                accesskeySecret.Text    = newCredentials.AccessTokenSecret;
            }
            else
            {
                CurrentStatusCount.Text = "Not Authorised";
                accesskey.Text          = "";
                accesskeySecret.Text    = "";
            }
        }
Пример #22
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));
 }