Пример #1
0
        private void PostTweet(string tweet, TwitterAccess twitteruser)
        {
            if (String.IsNullOrEmpty(tweet))
                return;


            var twitter = new TwitterHelper(twitteruser);

            // Successful event handler, navigate back if successful
            twitter.TweetCompletedEvent += (sender, e) =>
            {
                Dispatcher.BeginInvoke(() =>
                {
                    shellProgress.IsVisible = false;
                    MessageBox.Show("You have successfuly posted to your Twitter profile.");
                    browserAuth.Navigated -= Twitter_Navigated;
                });



                //if (NavigationService.CanGoBack)
                //    NavigationService.GoBack();
            };

            // Failed event handler, show error
            twitter.ErrorEvent += (sender, e) =>
            {
                Dispatcher.BeginInvoke(() =>
                {
                    shellProgress.IsVisible = false;
                    MessageBox.Show("There was an error. Please try again later.");
                    browserAuth.Navigated -= Twitter_Navigated;
                });
            };

            twitter.NewTweet(tweet);
        }
Пример #2
0
        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(() =>
                {
                    shellProgress.IsVisible = false;
                    MessageBox.Show("Authentication error.");
                });
                return;
            }

            TwitterHelper.SaveSetting("TwitterAccess", twitteruser);

            PostTweet(AppResource.ResourceManager.GetString("NewSession"), twitteruser);



        }