Esempio n. 1
0
        public TwitterHelper(TwitterAccess settings)
        {
            _twitterSettings = settings;

            if (_twitterSettings == null || String.IsNullOrEmpty(_twitterSettings.AccessToken) ||
               String.IsNullOrEmpty(_twitterSettings.AccessTokenSecret))
            {
                return;
            }

            _authorized = true;

            _credentials = new OAuthCredentials
            {
                Type = OAuthType.ProtectedResource,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                ConsumerKey = TwitterSettings.ConsumerKey,
                ConsumerSecret = TwitterSettings.ConsumerKeySecret,
                Token = _twitterSettings.AccessToken,
                TokenSecret = _twitterSettings.AccessTokenSecret,
                Version = TwitterSettings.OAuthVersion,
            };

            _client = new RestClient
            {
                Authority = "http://api.twitter.com",
                HasElevatedPermissions = true
            };
        }
Esempio n. 2
0
        public TwitterHelper(TwitterAccess settings)
        {
            _twitterSettings = settings;

            if (_twitterSettings == null || String.IsNullOrEmpty(_twitterSettings.AccessToken) ||
                String.IsNullOrEmpty(_twitterSettings.AccessTokenSecret))
            {
                return;
            }

            _authorized = true;

            _credentials = new OAuthCredentials
            {
                Type              = OAuthType.ProtectedResource,
                SignatureMethod   = OAuthSignatureMethod.HmacSha1,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                ConsumerKey       = TwitterSettings.ConsumerKey,
                ConsumerSecret    = TwitterSettings.ConsumerKeySecret,
                Token             = _twitterSettings.AccessToken,
                TokenSecret       = _twitterSettings.AccessTokenSecret,
                Version           = TwitterSettings.OAuthVersion,
            };

            _client = new RestClient
            {
                Authority = "http://api.twitter.com",
                HasElevatedPermissions = true
            };
        }
Esempio n. 3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _twitterSettings = Helper.LoadSetting<TwitterAccess>(Constants.TwitterAccess);
            if (_twitterSettings == null) return;

            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = !String.IsNullOrEmpty(_twitterSettings.AccessToken) && !String.IsNullOrEmpty(_twitterSettings.AccessTokenSecret);

            var detailItem = Helper.LoadSetting<TweetPageData>(Constants.TweetPageFileName);
            if (detailItem != null)
            {
                TweetTextBox.Content = detailItem.Tweet;

                var tweetPage = new TweetPageData
                {
                    Tweet = ""
                };

                // Save the detailpage object which the detailpage will load up
                Helper.SaveSetting(Constants.TweetPageFileName, tweetPage);
            }
        }
        private void RequestAccessTokenCompleted(RestRequest request, RestResponse response, object userstate)
        {
            var twitteruser = new TwitterAccess
            {
                AccessToken = GetQueryParameter(response.Content, "oauth_token"),
                AccessTokenSecret = GetQueryParameter(response.Content, "oauth_token_secret"),
                UserId = GetQueryParameter(response.Content, "user_id"),
                ScreenName = GetQueryParameter(response.Content, "screen_name")
            };

            if (String.IsNullOrEmpty(twitteruser.AccessToken) || String.IsNullOrEmpty(twitteruser.AccessTokenSecret))
            {
                Dispatcher.BeginInvoke(() => MessageBox.Show(response.Content));
                return;
            }

            Helper.SaveSetting(Constants.TwitterAccess, twitteruser);

            Dispatcher.BeginInvoke(() =>
            {
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
                else
                {
                    NavigationService.Navigate(new Uri("/Pages/MainPage.xaml", UriKind.Relative));
                }
            });
        }