Beispiel #1
0
    private static void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider)
    {
        // Authorization without callback url
        Console.Write("Getting request token...");
        OAuthToken oauthToken = 
            dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result;
        Console.WriteLine("Done.");

        OAuth1Parameters parameters = new OAuth1Parameters();
        string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(
            oauthToken.Value, parameters);
        Console.WriteLine("Redirect the user for authorization to {0}", authenticateUrl);
        Process.Start(authenticateUrl);
        Console.Write("Press [Enter] when authorization attempt has succeeded.");
        Console.ReadLine();

        Console.Write("Getting access token...");
        AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null);
        OAuthToken oauthAccessToken =
            dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
        Console.WriteLine("Done.");

        string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret };
        File.WriteAllLines(OAuthTokenFileName, oauthData);
    }
Beispiel #2
0
        /// <summary>
        /// Asynchronously exchange the authorized request token for an access token.
        /// </summary>
        /// <param name="requestToken">
        /// An authorized request token and verifier. The verifier will be ignored for OAuth 1.0 providers
        /// </param>
        /// <param name="additionalParameters">
        /// Any additional query parameters to be sent when exchanching for an access token.
        /// </param>
        /// <param name="operationCompleted">
        /// The <code>Action&lt;T&gt;</code> to perform when the asynchronous request completes.
        /// Provides the access token.
        /// </param>
        /// <returns>
        /// A <see cref="RestOperationCanceler"/> instance that allows to cancel the asynchronous operation.
        /// </returns>
        public RestOperationCanceler ExchangeForAccessTokenAsync(AuthorizedRequestToken requestToken, NameValueCollection additionalParameters, Action <RestOperationCompletedEventArgs <OAuthToken> > operationCompleted)
        {
            IDictionary <string, string> tokenParameters = new Dictionary <string, string>(2);

            tokenParameters.Add("oauth_token", requestToken.Value);
            if (version == OAuth1Version.Core10a)
            {
                tokenParameters.Add("oauth_verifier", requestToken.Verifier);
            }
            HttpEntity request = CreateExchangeForTokenRequest(this.accessTokenUrl, tokenParameters, additionalParameters, requestToken.Secret);

            return(this.restTemplate.PostForObjectAsync <NameValueCollection>(this.accessTokenUrl, request,
                                                                              r =>
            {
                if (r.Error == null)
                {
                    OAuthToken token = this.CreateOAuthToken(r.Response["oauth_token"], r.Response["oauth_token_secret"], r.Response);
                    operationCompleted(new RestOperationCompletedEventArgs <OAuthToken>(token, null, false, r.UserState));
                }
                else
                {
                    operationCompleted(new RestOperationCompletedEventArgs <OAuthToken>(null, r.Error, r.Cancelled, r.UserState));
                }
            }));
        }
        public static async Task<OAuthToken> authenticate2(OAuthToken tok, string pin)
        {
            var requestToken = new AuthorizedRequestToken(tok, pin);
            var meetupServiceProvider = new MeetupServiceProvider(MeetupApiKey, MeetupSecretKey);
            var oathAccessToken = meetupServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;

            return oathAccessToken;
        }
        // GET: /Twitter/Callback
        public ActionResult Callback(string oauth_verifier)
        {
            OAuthToken requestToken = Session["RequestToken"] as OAuthToken;
            AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, oauth_verifier);
            OAuthToken token = twitterProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;

            Session["AccessToken"] = token;

            return View();
        }
		public ActionResult Callback(string oauth_verifier)
		{
			var requestToken = Session["RequestToken"] as OAuthToken;
			var authorizedRequestToken = new AuthorizedRequestToken(requestToken, oauth_verifier);
			var token = _readabilityProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;

			Session["AccessToken"] = token;

			return RedirectToAction("Index");
		}
        // GET: /Twitter/Callback
        public ActionResult Callback(string oauth_verifier)
        {
            OAuthToken requestToken = Session["RequestToken"] as OAuthToken;
            AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, oauth_verifier);
            OAuthToken token = twitterProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;

            Session["AccessToken"] = token;

            ITwitter twitterClient = twitterProvider.GetApi(token.Value, token.Secret);
            TwitterProfile profile = twitterClient.UserOperations.GetUserProfileAsync().Result;
            return View(profile);
        }
        // GET: /LinkedIn/Callback
        public ActionResult CallbackFullProfile(string oauth_verifier)
        {
            var requestToken = Session["RequestToken"] as OAuthToken;
            var authorizedRequestToken = new AuthorizedRequestToken(requestToken, oauth_verifier);
            OAuthToken token = linkedInProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;

            Session["AccessToken"] = token;

            ILinkedIn linkedInClient = linkedInProvider.GetApi(token.Value, token.Secret);
            var fullProfile = linkedInClient.ProfileOperations.GetUserFullProfileAsync().Result;
            return View("FullProfile", fullProfile);
        }
Beispiel #8
0
		private static void Main(string[] args)
		{
			try
			{
				var meetupServiceProvider = new MeetupServiceProvider(MeetupApiKey, MeetupApiSecret);

				/* OAuth 'dance' */

				// Authentication using Out-of-band/PIN Code Authentication
				Console.Write("Getting request token...");
				var oauthToken = meetupServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
				Console.WriteLine("Done");

				var authenticateUrl = meetupServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
				Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
				Process.Start(authenticateUrl);
				Console.WriteLine("Enter PIN Code from Meetup authorization page:");
				var pinCode = Console.ReadLine();

				Console.Write("Getting access token...");
				var requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
				var oauthAccessToken = meetupServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
				Console.WriteLine("Done");

				/* API */

				var meetup = meetupServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

				meetup.RestOperations.GetForObjectAsync<string>("https://api.meetup.com/2/members?member_id=" + MemberId)
					.ContinueWith(task => Console.WriteLine("Result: " + task.Result));
			}
			catch (AggregateException ae)
			{
				ae.Handle(ex =>
				{
				    if (ex is MeetupApiException)
				    {
				        Console.WriteLine(ex.Message);
				        return true;
				    }
				    return false;
				});
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex);
			}
			finally
			{
				Console.WriteLine("--- hit <return> to quit ---");
				Console.ReadLine();
			}
		}
Beispiel #9
0
		private static void Main(string[] args)
		{
			try
			{
				var bitbucketServiceProvider = new BitbucketServiceProvider(BitbucketApiKey, BitbucketApiSecret);

				/* OAuth 'dance' */

				// Authentication using Out-of-band/PIN Code Authentication
				Console.Write("Getting request token...");
				var oauthToken = bitbucketServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
				Console.WriteLine("Done");

				var authenticateUrl = bitbucketServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
				Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
				Process.Start(authenticateUrl);
				Console.WriteLine("Enter PIN Code from Bitbucket authorization page:");
				var pinCode = Console.ReadLine();

				Console.Write("Getting access token...");
				var requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
				var oauthAccessToken = bitbucketServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
				Console.WriteLine("Done");

				/* API */

				var bitbucket = bitbucketServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

				bitbucket.RestOperations.GetForObjectAsync<JsonValue>("https://api.bitbucket.org/1.0/users/" + Username)
					.ContinueWith(task => Console.WriteLine("Result: " + task.Result.ToString()));
			}
			catch (AggregateException ae)
			{
				ae.Handle(ex =>
				{
				    if (ex is BitbucketApiException)
				    {
				        Console.WriteLine(ex.Message);
				        return true;
				    }
				    return false;
				});
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex);
			}
			finally
			{
				Console.WriteLine("--- hit <return> to quit ---");
				Console.ReadLine();
			}
		}
 private async static Task<OAuthToken>  authenticate()
 {
     var meetupServiceProvider = new MeetupServiceProvider(MeetupApiKey, MeetupSecretKey);
     var oauthToken = await meetupServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null);
     var authenticateUrl = meetupServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
     Process.Start(authenticateUrl);
     Console.WriteLine("Enter the pin");
     var pinCode = Console.ReadLine();
     var requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
     var oauthAccessToken = await meetupServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null);
     Console.WriteLine("Done");
     return oauthAccessToken;
 }
        // GET: /Dropbox/Callback
        public ActionResult Callback()
        {
            OAuthToken requestToken = Session["RequestToken"] as OAuthToken;
            AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, null);
            OAuthToken token = dropboxProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;

            Session["TokenValue"] = token.Value;
            Session["TokenSecret"] = token.Secret;

            IDropbox dropboxClient = dropboxProvider.GetApi(token.Value, token.Secret);
            DropboxProfile profile = dropboxClient.GetUserProfileAsync().Result;
            return View(profile);
        }
Beispiel #12
0
        /// <summary>
        /// Exchange the authorized request token for an access token.
        /// </summary>
        /// <param name="requestToken">
        /// An authorized request token and verifier. The verifier will be ignored for OAuth 1.0 providers.
        /// </param>
        /// <param name="additionalParameters">
        /// Any additional query parameters to be sent when exchanching for an access token.
        /// </param>
        /// <returns>The access token.</returns>
        public OAuthToken ExchangeForAccessToken(AuthorizedRequestToken requestToken, NameValueCollection additionalParameters)
        {
            IDictionary <string, string> tokenParameters = new Dictionary <string, string>(2);

            tokenParameters.Add("oauth_token", requestToken.Value);
            if (version == OAuth1Version.Core10a)
            {
                tokenParameters.Add("oauth_verifier", requestToken.Verifier);
            }
            HttpEntity          request  = CreateExchangeForTokenRequest(this.accessTokenUrl, tokenParameters, additionalParameters, requestToken.Secret);
            NameValueCollection response = this.restTemplate.PostForObject <NameValueCollection>(this.accessTokenUrl, request);

            return(this.CreateOAuthToken(response["oauth_token"], response["oauth_token_secret"], response));
        }
        //Save the newly became authorization strings in a file to reuse them later (not authorize again every time)
        private void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider)
        {
            // Authorization without callback url
            OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null, null).Result;

            OAuth1Parameters parameters = new OAuth1Parameters();
            string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(
                oauthToken.Value, parameters);
            Process.Start(authenticateUrl);
            AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null);
            OAuthToken oauthAccessToken =
                dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;

            string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret };
            File.WriteAllLines(OAuthTokenFileName, oauthData);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((Request.Cookies["requestTokenValue"] == null) || (Request.Cookies["requestTokenSecret"] == null))
            {
                DropboxAuth();
            }

            if ((Request.Cookies["TokenValue"] == null) || (Request.Cookies["TokenSecret"] == null))
            {
                OAuthToken requestToken = new OAuthToken(Request.Cookies["requestTokenValue"].Value, Request.Cookies["requestTokenSecret"].Value);
                AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, null);
                OAuthToken token = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;
                Response.Cookies["TokenValue"].Value = token.Value;
                Response.Cookies["TokenSecret"].Value = token.Secret;
            }
        }
 private async static Task<OAuthToken> authenticate()
 {
     var meetupServiceProvider = new MeetupServiceProvider(MeetupApiKey, MeetupApiSecret);
     Console.Write("Getting request token...");
     var oauthToken = await meetupServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null);
     Console.WriteLine("Done");
     var authenticateUrl = meetupServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
     Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
     Process.Start(authenticateUrl);
     Console.WriteLine("Enter PIN Code from Meetup authorization page:");
     var pinCode = Console.ReadLine();
     Console.Write("Getting access token...");
     var requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
     var oauthAccessToken = await meetupServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null);
     Console.WriteLine("Done");
     return oauthAccessToken;
 }
        private static async Task<OAuthToken> authenticate()
        {
            var meetupServiceProvider = new MeetupServiceProvider(MeetupApiKey, MeetupSecretKey);
            //OAuth Dance//
            var oauthToken = await meetupServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null);
            var authenticateUrl = meetupServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
            Process.Start(authenticateUrl);

            Console.WriteLine("Enter the pin from meetup.com");
            string pin = Console.ReadLine();

            var requestToken = new AuthorizedRequestToken(oauthToken, pin);
            var oathAccessToken = meetupServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;

            return oathAccessToken;

        }
Beispiel #17
0
 public static void DropboxAuthEnd(this SessionState _sessionState)
 {
     AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(AppCache.requestToken, null);
     AppCache.token = AppCache.dropboxProvider.OAuthOperations.ExchangeForAccessTokenAsync(authorizedRequestToken, null).Result;
     OAuthTokenEx o = _sessionState.GetOAuthToken().FirstOrDefault();
     if (o == null)
     {
         o = new OAuthTokenEx();
         _sessionState.SaveNewToken(o);
     }
     else
     {
         dynamic pd = (new JsonSerializer()).Deserialize(new JsonTextReader(new StringReader(AppCache.AESProvider.DecryptString(o.PrivateData))));
         if (pd.Secret.Value != AppCache.token.Secret || pd.Value.Value != AppCache.token.Value)
             _sessionState.SaveNewToken(o);
     }
 }
Beispiel #18
0
        /// <summary>
        /// Asynchronously exchange the authorized request token for an access token.
        /// </summary>
        /// <param name="requestToken">
        /// An authorized request token and verifier. The verifier will be ignored for OAuth 1.0 providers
        /// </param>
        /// <param name="additionalParameters">
        /// Any additional query parameters to be sent when exchanching for an access token.
        /// </param>
        /// <returns>
        /// A <code>Task&lt;T&gt;</code> that represents the asynchronous operation that can return the access token.
        /// </returns>
        public Task <OAuthToken> ExchangeForAccessTokenAsync(AuthorizedRequestToken requestToken, NameValueCollection additionalParameters)
        {
            IDictionary <string, string> tokenParameters = new Dictionary <string, string>(2);

            tokenParameters.Add("oauth_token", requestToken.Value);
            if (version == OAuth1Version.Core10a)
            {
                tokenParameters.Add("oauth_verifier", requestToken.Verifier);
            }
            HttpEntity request = CreateExchangeForTokenRequest(this.accessTokenUrl, tokenParameters, additionalParameters, requestToken.Secret);

            return(this.restTemplate.PostForObjectAsync <NameValueCollection>(this.accessTokenUrl, request)
                   .ContinueWith <OAuthToken>(task =>
            {
                return this.CreateOAuthToken(task.Result["oauth_token"], task.Result["oauth_token_secret"], task.Result);
            }, TaskContinuationOptions.ExecuteSynchronously));
        }
        private static async  Task<OAuthToken> authenticate()
        {
            //setup meetupServiceProvider - this is part of the authentication process (???)
            var meetupServiceProvider = new MeetupServiceProvider(MeetupApiKey, MeetupSecretKey);

            /* OAuth Dance */
            var oauthToken = meetupServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;

            var authenticateUrl = meetupServiceProvider.OAuthOperations.BuildAuthenticateUrl(oauthToken.Value, null);

            Process.Start(authenticateUrl);  //opens up web browser

            Console.WriteLine("Enter the pin from meetup.com");
            string pin = Console.ReadLine();

            var requestToken = new AuthorizedRequestToken(oauthToken, pin);
            var oauthAccessToken = meetupServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;

            return oauthAccessToken;
        }
        public ActionResult Callback(string oauth_verifier)
        {
            OAuthToken requestToken = Session.GetTwitterRequestToken();
            var authorizedRequestToken = new AuthorizedRequestToken(requestToken, oauth_verifier);
            OAuthToken token =
                TwitterProvider
                    .OAuthOperations
                    .ExchangeForAccessTokenAsync(authorizedRequestToken, null)
                    .Result;

            Session.SetTwitterAccessToken(token);

            //post action
            string status = Session.GetTwitterNewStatus();
            if (!string.IsNullOrEmpty(status))
            {
                return SendUpdate(new StatusViewModel {Status = status}, token);
            }

            return Content("Yes");
        }
        public void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider, string OAuthTokenFileName)
        {
            OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null);

               OAuth1Parameters parameters = new OAuth1Parameters();
            string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(
                oauthToken.Value, parameters);

            //Process.Start(authenticateUrl);

            AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null);
            OAuthToken oauthAccessToken =
                dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null);

            string[] oauthData = new string[]
            {
                oauthAccessToken.Value,
                oauthAccessToken.Secret
            };
            File.WriteAllLines(OAuthTokenFileName, oauthData);
        }
        private void AuthorizeAppOAuth(DropboxServiceProvider dropboxServiceProvider)
        {
            OAuthToken oauthToken = dropboxServiceProvider
                .OAuthOperations
                .FetchRequestTokenAsync(null, null).Result;

            OAuth1Parameters parameters = new OAuth1Parameters();
            string authenticateUrl = dropboxServiceProvider
                .OAuthOperations
                .BuildAuthorizeUrl(oauthToken.Value, parameters);

            Process.Start(authenticateUrl);
            Console.Write("Press [Enter] when authorization attempt has succeeded.");
            Console.ReadLine();

            AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null);
            OAuthToken oauthAccessToken =
                dropboxServiceProvider
                .OAuthOperations
                .ExchangeForAccessTokenAsync(requestToken, null).Result;

            string[] oauthData = new string[] { oauthAccessToken.Value, oauthAccessToken.Secret };
            File.WriteAllLines(OAuthTokenFileName, oauthData);
        }
Beispiel #23
0
        static void Main(string[] args)
        {
#if NET_4_0
            try
            {
                TwitterServiceProvider twitterServiceProvider = new TwitterServiceProvider(TwitterConsumerKey, TwitterConsumerSecret);

                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                OAuthToken oauthToken = twitterServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
                Console.WriteLine("Done");

                string authenticateUrl = twitterServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from Twitter authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = twitterServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
                Console.WriteLine("Done");

                /* API */

                ITwitter twitter = twitterServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                Console.WriteLine("Enter your status message:");
                string message = Console.ReadLine();

                twitter.UpdateStatusAsync(message).Wait();
                Console.WriteLine("Status updated!");
            }
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                    {
                        if (ex is HttpResponseException)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(((HttpResponseException)ex).GetResponseBodyAsString());
                            return true;
                        }
                        return false;
                    });
            }
#else
            try
            {
                TwitterServiceProvider twitterServiceProvider = new TwitterServiceProvider(TwitterConsumerKey, TwitterConsumerSecret);

                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                OAuthToken oauthToken = twitterServiceProvider.OAuthOperations.FetchRequestToken("oob", null);
                Console.WriteLine("Done");

                string authenticateUrl = twitterServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from Twitter authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = twitterServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null);
                Console.WriteLine("Done");

                /* API */

                ITwitter twitter = twitterServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                Console.WriteLine("Enter your status message:");
                string message = Console.ReadLine();
                
                twitter.UpdateStatus(message);
                Console.WriteLine("Status updated!");
            }
            catch (HttpResponseException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.GetResponseBodyAsString());
            }
#endif
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Console.WriteLine("--- hit <return> to quit ---");
                Console.ReadLine();
            }
        }
Beispiel #24
0
        private void ContinueLinkApp(AuthenticationToken token)
        {
            try
            {
                // Get access token either from parameter or from API
                OAuthToken oauthAccessToken = null;
                if (token == null)
                {
                    AuthorizedRequestToken requestToken = new AuthorizedRequestToken(_oauthToken, null);
                    oauthAccessToken = _dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
                }
                else
                {
                    oauthAccessToken = new OAuthToken(token.Value, token.Secret);
                }

                if (OnCloudAuthenticationStatusChanged != null)
                    OnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType.RequestAccessToken);

                // Get Dropbox API instance
                _dropbox = _dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag;

                // Test Dropbox API connection (get user name from profile)
                DropboxProfile profile = _dropbox.GetUserProfileAsync().Result;
                HasLinkedAccount = true;

                // Save token to hard disk
                SaveTokenToDisk(new AuthenticationToken() {
                    Value = oauthAccessToken.Value, 
                    Secret = oauthAccessToken.Secret,
                    UserName = profile.DisplayName
                });
                
                if (OnCloudAuthenticationStatusChanged != null)
                    OnCloudAuthenticationStatusChanged(CloudAuthenticationStatusType.ConnectedToDropbox);
            }
            catch (AggregateException ae)
            {
                HasLinkedAccount = false;
                ae.Handle(ex =>
                {
                    if (ex is DropboxApiException)
                    {
                        Console.WriteLine(ex.Message);
                        return true;
                    }
                    return false;
                });
            }
        }
        static void Main(string[] args)
        {
            try
            {
                TwitterServiceProvider twitterServiceProvider = new TwitterServiceProvider(TwitterConsumerKey, TwitterConsumerSecret);

#if NET_4_0
                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                OAuthToken oauthToken = twitterServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
                Console.WriteLine("Done");

                string authenticateUrl = twitterServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from Twitter authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = twitterServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
                Console.WriteLine("Done");

                /* API */

                ITwitter twitter = twitterServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

                twitter.UserOperations.GetUserProfileAsync("brbaia")
                    .ContinueWith(task => Console.WriteLine("brbaia is " + task.Result.Name));

                // Use step by step debugging
/*
                // IBlockOperations
                TwitterProfile blockedProfile = twitter.BlockOperations.BlockAsync("brbaia").Result;
                CursoredList<TwitterProfile> blockedIserProfiles = twitter.BlockOperations.GetBlockedUsersAsync().Result;
                CursoredList<long> blockedUserIds = twitter.BlockOperations.GetBlockedUserIdsAsync().Result;
                blockedProfile = twitter.BlockOperations.UnblockAsync(blockedProfile.ID).Result;

                // IDirectMessageOperations
                IList<DirectMessage> directMessagesSent = twitter.DirectMessageOperations.GetDirectMessagesSentAsync().Result;
                IList<DirectMessage> directMessagesReceived = twitter.DirectMessageOperations.GetDirectMessagesReceivedAsync().Result;
                DirectMessage directMessage = twitter.DirectMessageOperations.SendDirectMessageAsync("brbaia", "Hi from #Spring.NET Social Twitter!").Result;
                directMessage = twitter.DirectMessageOperations.GetDirectMessageAsync(directMessage.ID).Result;
                directMessage = twitter.DirectMessageOperations.DeleteDirectMessageAsync(directMessage.ID).Result;

                // IFriendOperations
                CursoredList<TwitterProfile> followers = twitter.FriendOperations.GetFollowersAsync().Result;
                CursoredList<TwitterProfile> friends = twitter.FriendOperations.GetFriendsAsync().Result;
                TwitterProfile newFriend = twitter.FriendOperations.FollowAsync("brbaia").Result;
                twitter.FriendOperations.EnableNotificationsAsync("brbaia").Wait();

                // IGeoOperations
                IList<Place> places = twitter.GeoOperations.SearchAsync(37.7821120598956, -122.400612831116).Result;

                // IListOperations
                IList<UserList> myLists = twitter.ListOperations.GetListsAsync().Result;
                IList<UserList> s2Lists = twitter.ListOperations.GetListsAsync("SpringSource").Result;
                IList<TwitterProfile> listMembers = twitter.ListOperations.GetListMembersAsync(s2Lists[0].ID).Result;
                IList<TwitterProfile> listSubscribers = twitter.ListOperations.GetListSubscribersAsync(s2Lists[0].ID).Result;
                IList<Tweet> listTweets = twitter.ListOperations.GetListStatusesAsync(s2Lists[0].ID).Result;
                CursoredList<UserList> listMemberships = twitter.ListOperations.GetMembershipsAsync(listMembers[0].ID).Result;
                UserList myNewList = twitter.ListOperations.CreateListAsync("My list", "List description", true).Result;
                twitter.ListOperations.AddToListAsync(myNewList.ID, "brbaia").Wait();
                twitter.ListOperations.DeleteListAsync(myNewList.ID).Wait();

                // ISearchOperations
                SearchResults searchResults = twitter.SearchOperations.SearchAsync("#spring").Result;
                SavedSearch savedSearch = twitter.SearchOperations.CreateSavedSearchAsync("@brbaia").Result;
                IList<SavedSearch> savedSearches = twitter.SearchOperations.GetSavedSearchesAsync().Result;
                twitter.SearchOperations.DeleteSavedSearchAsync(savedSearch.ID).Wait();
                Trends globalTrends = twitter.SearchOperations.GetTrendsAsync(1).Result;

                // ITimelineOperations
                Tweet tweet = twitter.TimelineOperations.UpdateStatusAsync(
                    "Hi from #Spring.NET Social Twitter! http://bit.ly/x2rvlC", new AssemblyResource("Image.png", typeof(Program))).Result;
                twitter.TimelineOperations.DeleteStatusAsync(tweet.ID).Wait();
                IList<Tweet> homeTimeline = twitter.TimelineOperations.GetHomeTimelineAsync().Result;
                IList<Tweet> userTimeline = twitter.TimelineOperations.GetUserTimelineAsync().Result;
                IList<Tweet> mentions = twitter.TimelineOperations.GetMentionsAsync().Result;
                IList<Tweet> retweetsOfMe = twitter.TimelineOperations.GetRetweetsOfMeAsync().Result;
                IList<Tweet> retweets = twitter.TimelineOperations.GetRetweetsAsync(homeTimeline[0].ID).Result;
                IList<Tweet> favorites = twitter.TimelineOperations.GetFavoritesAsync().Result;

                // IUserOperations
                TwitterProfile userProfile = twitter.UserOperations.GetUserProfileAsync().Result;
                IList<TwitterProfile> searchProfiles = twitter.UserOperations.SearchForUsersAsync("spring").Result;
                IList<RateLimitStatus> limits = twitter.UserOperations.GetRateLimitStatusAsync("users", "search", "statuses").Result;
*/
            }
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                    {
                        if (ex is TwitterApiException)
                        {
                            Console.WriteLine(ex.Message);
                            return true;
                        }
                        return false;
                    });
            }
#else
                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                OAuthToken oauthToken = twitterServiceProvider.OAuthOperations.FetchRequestToken("oob", null);
                Console.WriteLine("Done");

                string authenticateUrl = twitterServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from Twitter authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = twitterServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null);
                Console.WriteLine("Done");

                /* API */

                ITwitter twitter = twitterServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

                TwitterProfile profile = twitter.UserOperations.GetUserProfile("brbaia");
                Console.WriteLine("brbaia is " + profile.Name);

                // Use step by step debugging
/*
                // IBlockOperations
                TwitterProfile blockedProfile = twitter.BlockOperations.Block("brbaia");
                CursoredList<TwitterProfile> blockedIserProfiles = twitter.BlockOperations.GetBlockedUsers();
                CursoredList<long> blockedUserIds = twitter.BlockOperations.GetBlockedUserIds();
                blockedProfile = twitter.BlockOperations.Unblock(blockedProfile.ID);

                // IDirectMessageOperations
                IList<DirectMessage> directMessagesSent = twitter.DirectMessageOperations.GetDirectMessagesSent();
                IList<DirectMessage> directMessagesReceived = twitter.DirectMessageOperations.GetDirectMessagesReceived();
                DirectMessage directMessage = twitter.DirectMessageOperations.SendDirectMessage("brbaia", "Hi from #Spring.NET Social Twitter!");
                directMessage = twitter.DirectMessageOperations.GetDirectMessage(directMessage.ID);
                directMessage = twitter.DirectMessageOperations.DeleteDirectMessage(directMessage.ID);

                // IFriendOperations
                CursoredList<TwitterProfile> followers = twitter.FriendOperations.GetFollowers();
                CursoredList<TwitterProfile> friends = twitter.FriendOperations.GetFriends();
                TwitterProfile newFriend = twitter.FriendOperations.Follow("brbaia");
                twitter.FriendOperations.EnableNotifications("brbaia");

                // IGeoOperations
                IList<Place> places = twitter.GeoOperations.Search(37.7821120598956, -122.400612831116);

                // IListOperations
                IList<UserList> myLists = twitter.ListOperations.GetLists();
                IList<UserList> s2Lists = twitter.ListOperations.GetLists("SpringSource");
                IList<TwitterProfile> listMembers = twitter.ListOperations.GetListMembers(s2Lists[0].ID);
                IList<TwitterProfile> listSubscribers = twitter.ListOperations.GetListSubscribers(s2Lists[0].ID);
                IList<Tweet> listTweets = twitter.ListOperations.GetListStatuses(s2Lists[0].ID);
                CursoredList<UserList> listMemberships = twitter.ListOperations.GetMemberships(listMembers[0].ID);
                UserList myNewList = twitter.ListOperations.CreateList("My list", "List description", true);
                twitter.ListOperations.AddToList(myNewList.ID, "brbaia");
                twitter.ListOperations.DeleteList(myNewList.ID);

                // ISearchOperations
                SearchResults searchResults = twitter.SearchOperations.Search("#spring");
                SavedSearch savedSearch = twitter.SearchOperations.CreateSavedSearch("@brbaia");
                IList<SavedSearch> savedSearches = twitter.SearchOperations.GetSavedSearches();
                twitter.SearchOperations.DeleteSavedSearch(savedSearch.ID);
                Trends globalTrends = twitter.SearchOperations.GetTrends(1);

                // ITimelineOperations
                Tweet tweet = twitter.TimelineOperations.UpdateStatus(
                    "Hi from #Spring.NET Social Twitter! http://bit.ly/x2rvlC", new AssemblyResource("Image.png", typeof(Program)));
                twitter.TimelineOperations.DeleteStatus(tweet.ID);
                IList<Tweet> homeTimeline = twitter.TimelineOperations.GetHomeTimeline();
                IList<Tweet> userTimeline = twitter.TimelineOperations.GetUserTimeline();
                IList<Tweet> mentions = twitter.TimelineOperations.GetMentions();
                IList<Tweet> retweetsOfMe = twitter.TimelineOperations.GetRetweetsOfMe();
                IList<Tweet> retweets = twitter.TimelineOperations.GetRetweets(homeTimeline[0].ID);
                IList<Tweet> favorites = twitter.TimelineOperations.GetFavorites();

                // IUserOperations
                TwitterProfile userProfile = twitter.UserOperations.GetUserProfile();
                IList<TwitterProfile> searchProfiles = twitter.UserOperations.SearchForUsers("spring");
                IList<RateLimitStatus> limits = twitter.UserOperations.GetRateLimitStatus("users", "search", "statuses");
*/
            }
        static void Main(string[] args)
        {
            try
            {
                DropboxServiceProvider dropboxServiceProvider = new DropboxServiceProvider(DropboxAppKey, DropboxAppSecret, AccessLevel.Full);

#if NET_4_0
                /* OAuth 1.0 'dance' */

                // Authorization without callback url
                Console.Write("Getting request token...");
                OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestTokenAsync(null , null).Result;
                Console.WriteLine("Done");

                OAuth1Parameters parameters = new OAuth1Parameters();
                //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website
                string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters);
                Console.WriteLine("Redirect user for authorization");
                Process.Start(authenticateUrl);
                Console.Write("Press any key when authorization attempt has succeeded");
                Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null);
                OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
                Console.WriteLine("Done");

                /* API */

                IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag;

                DropboxProfile profile = dropbox.GetUserProfileAsync().Result;
                Console.WriteLine("Hi " + profile.DisplayName + "!");

                // Use step by step debugging, or not             
/*
                DeltaPage deltaPage = dropbox.DeltaAsync(null).Result;
                Entry createFolderEntry = dropbox.CreateFolderAsync("Spring Social").Result;
                Entry uploadFileEntry = dropbox.UploadFileAsync(
                    new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"),
                    "/Spring Social/File.txt", true, null, CancellationToken.None).Result;
                FileRef fileRef = dropbox.CreateFileRefAsync("Spring Social/File.txt").Result;
                Entry copyRefEntry = dropbox.CopyFileRefAsync(fileRef.Value, "Spring Social/File_copy_ref.txt").Result;
                Entry copyEntry = dropbox.CopyAsync("Spring Social/File.txt", "Spring Social/File_copy.txt").Result;
                Entry deleteEntry = dropbox.DeleteAsync("Spring Social/File.txt").Result;
                Entry moveEntry = dropbox.MoveAsync("Spring Social/File_copy.txt", "Spring Social/File.txt").Result;
                dropbox.DownloadFileAsync("Spring Social/File.txt")
                    .ContinueWith(task =>
                    {
                        Console.WriteLine("File '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size);
                        // Save file to "C:\Spring Social.txt"
                        using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create))
                        {
                            fileStream.Write(task.Result.Content, 0, task.Result.Content.Length);
                        }
                    });
                Entry folderMetadata = dropbox.GetMetadataAsync("Spring Social").Result;
                IList<Entry> revisionsEntries = dropbox.GetRevisionsAsync("Spring Social/File.txt").Result;
                Entry restoreEntry = dropbox.RestoreAsync("Spring Social/File.txt", revisionsEntries[2].Revision).Result;
                IList<Entry> searchResults = dropbox.SearchAsync("Spring Social/", ".txt").Result;
                DropboxLink shareableLink = dropbox.GetShareableLinkAsync("Spring Social/File.txt").Result;
                DropboxLink mediaLink = dropbox.GetMediaLinkAsync("Spring Social/File.txt").Result;
                Entry uploadImageEntry = dropbox.UploadFileAsync(
                    new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"),
                    "/Spring Social/Image.png", true, null, CancellationToken.None).Result;
                dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium)
                    .ContinueWith(task =>
                    {
                        Console.WriteLine("Thumbnail '{0}' downloaded ({1})", task.Result.Metadata.Path, task.Result.Metadata.Size);
                        // Save file to "C:\Thumbnail_Medium.png"
                        using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create))
                        {
                            fileStream.Write(task.Result.Content, 0, task.Result.Content.Length);
                        }
                    });
*/
            }
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                    {
                        if (ex is DropboxApiException)
                        {
                            Console.WriteLine(ex.Message);
                            return true;
                        }
                        return false;
                    });
            }
#else
                /* OAuth 1.0 'dance' */

                // Authorization without callback url
                Console.Write("Getting request token...");
                OAuthToken oauthToken = dropboxServiceProvider.OAuthOperations.FetchRequestToken(null, null);
                Console.WriteLine("Done");

                OAuth1Parameters parameters = new OAuth1Parameters();
                //parameters.Add("locale", CultureInfo.CurrentUICulture.IetfLanguageTag); // for a localized version of the authorization website
                string authenticateUrl = dropboxServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, parameters);
                Console.WriteLine("Redirect user for authorization");
                Process.Start(authenticateUrl);
                Console.Write("Press any key when authorization attempt has succeeded");
                Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, null);
                OAuthToken oauthAccessToken = dropboxServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null);
                Console.WriteLine("Done");

                /* API */

                IDropbox dropbox = dropboxServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                //dropbox.Locale = CultureInfo.CurrentUICulture.IetfLanguageTag;

                DropboxProfile profile = dropbox.GetUserProfile();
                Console.WriteLine("Hi " + profile.DisplayName + "!");

                // Use step by step debugging, or not
/*
                DeltaPage deltaPage = dropbox.Delta(null);
                Entry createFolderEntry = dropbox.CreateFolder("Spring Social");
                Entry uploadFileEntry = dropbox.UploadFile(
                    new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/File.txt"),
                    "/Spring Social/File.txt", true, null);
                FileRef fileRef = dropbox.CreateFileRef("Spring Social/File.txt");
                Entry copyRefEntry = dropbox.CopyFileRef(fileRef.Value, "Spring Social/File_copy_ref.txt");
                Entry copyEntry = dropbox.Copy("Spring Social/File.txt", "Spring Social/File_copy.txt");
                Entry deleteEntry = dropbox.Delete("Spring Social/File.txt");
                Entry moveEntry = dropbox.Move("Spring Social/File_copy.txt", "Spring Social/File.txt");
                var fileCanceler = dropbox.DownloadFileAsync("Spring Social/File.txt",
                    r =>
                    {
                        Console.WriteLine("File '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size);
                        // Save file to "C:\Spring Social.txt"
                        using (FileStream fileStream = new FileStream(@"C:\Spring Social.txt", FileMode.Create))
                        {
                            fileStream.Write(r.Response.Content, 0, r.Response.Content.Length);
                        }
                    });
                Entry folderMetadata = dropbox.GetMetadata("Spring Social");
                IList<Entry> revisionsEntries = dropbox.GetRevisions("Spring Social/File.txt");
                Entry restoreEntry = dropbox.Restore("Spring Social/File.txt", revisionsEntries[2].Revision);
                IList<Entry> searchResults = dropbox.Search("Spring Social/", ".txt");
                DropboxLink shareableLink = dropbox.GetShareableLink("Spring Social/File.txt");
                DropboxLink mediaLink = dropbox.GetMediaLink("Spring Social/File.txt");
                Entry uploadImageEntry = dropbox.UploadFile(
                    new AssemblyResource("assembly://Spring.ConsoleQuickStart/Spring.ConsoleQuickStart/Image.png"),
                    "/Spring Social/Image.png", true, null);
                var thumbnailCanceler = dropbox.DownloadThumbnailAsync("Spring Social/Image.png", ThumbnailFormat.Png, ThumbnailSize.Medium, 
                    r =>
                    {
                        Console.WriteLine("Thumbnail '{0}' downloaded ({1})", r.Response.Metadata.Path, r.Response.Metadata.Size);
                        // Save file to "C:\Thumbnail_Medium.png"
                        using (FileStream fileStream = new FileStream(@"C:\Thumbnail_Medium.png", FileMode.Create))
                        {
                            fileStream.Write(r.Response.Content, 0, r.Response.Content.Length);
                        }
                    });
*/
            }
 /// <summary>
 /// Asynchronously exchange the authorized request token for an access token.
 /// </summary>
 /// <param name="requestToken">
 /// An authorized request token and verifier. The verifier will be ignored for OAuth 1.0 providers
 /// </param>
 /// <param name="additionalParameters">
 /// Any additional query parameters to be sent when fetching the access token
 /// </param>
 /// <returns>
 /// A <code>Task&lt;T&gt;</code> that represents the asynchronous operation that can return the access token.
 /// </returns>
 public Task<OAuthToken> ExchangeForAccessTokenAsync(AuthorizedRequestToken requestToken, NameValueCollection additionalParameters)
 {
     IDictionary<string, string> tokenParameters = new Dictionary<string, string>(2);
     tokenParameters.Add("oauth_token", requestToken.Value);
     if (version == OAuth1Version.Core10a)
     {
         tokenParameters.Add("oauth_verifier", requestToken.Verifier);
     }
     HttpEntity request = CreateExchangeForTokenRequest(this.accessTokenUrl, tokenParameters, additionalParameters, requestToken.Secret);
     return this.restTemplate.PostForObjectAsync<NameValueCollection>(this.accessTokenUrl, request)
         .ContinueWith<OAuthToken>(task =>
         {
             return this.CreateOAuthToken(task.Result["oauth_token"], task.Result["oauth_token_secret"], task.Result);
         });
 }
Beispiel #28
0
		private static void Main(string[] args)
		{
			try
			{
				var readabilityServiceProvider = new ReadabilityServiceProvider(ReadabilityApiKey, ReadabilityApiSecret);

				/* OAuth 'dance' */

				// Authentication using Out-of-band/PIN Code Authentication
				Console.Write("Getting request token...");
				var oauthToken = readabilityServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
				Console.WriteLine("Done");

				var authenticateUrl = readabilityServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
				Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
				Process.Start(authenticateUrl);
				Console.WriteLine("Enter PIN Code from Readability authorization page:");
				var pinCode = Console.ReadLine();

				Console.Write("Getting access token...");
				var requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
				var oauthAccessToken = readabilityServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
				Console.WriteLine("Done");

				/* API */

				var readability = readabilityServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

				readability.UserOperations.GetUserAsync()
					.ContinueWith(task => Console.WriteLine("Username: "******"All bookmarks: " + task.Result.Bookmarks.Count));

				readability.BookmarkOperations.GetReadingListBookmarksAsync(1, 50)
					.ContinueWith(task => Console.WriteLine("Reading list bookmarks: " + task.Result.Bookmarks.Count));

				readability.BookmarkOperations.GetFavoriteBookmarksAsync(1, 50)
					.ContinueWith(task => Console.WriteLine("Favorite bookmarks: " + task.Result.Bookmarks.Count));

				readability.BookmarkOperations.GetArchivedBookmarksAsync(1, 50)
					.ContinueWith(task => Console.WriteLine("Archived bookmarks: " + task.Result.Bookmarks.Count));
			}
			catch (AggregateException ae)
			{
				ae.Handle(ex =>
				{
				    if (ex is ReadabilityApiException)
				    {
				        Console.WriteLine(ex.Message);
				        return true;
				    }
				    return false;
				});
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex);
			}
			finally
			{
				Console.WriteLine("--- hit <return> to quit ---");
				Console.ReadLine();
			}
		}
        static void Main(string[] args)
        {
            try
            {
                LinkedInServiceProvider linkedInServiceProvider = new LinkedInServiceProvider(LinkedInApiKey, LinkedInApiSecret);

#if NET_4_0
                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                NameValueCollection parameters = new NameValueCollection();
                //parameters.Add("scope", "r_basicprofile r_emailaddress");
                OAuthToken oauthToken = linkedInServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", parameters).Result;
                Console.WriteLine("Done");

                string authenticateUrl = linkedInServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from LinkedIn authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = linkedInServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
                Console.WriteLine("Done");

                /* API */

                ILinkedIn linkedIn = linkedInServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

                LinkedInProfile profile = linkedIn.ProfileOperations.GetUserProfileAsync().Result;
                Console.WriteLine("Authenticated user is " + profile.FirstName + " " + profile.LastName);

                // Use step by step debugging             
/*
                LinkedInProfile profileById = linkedIn.ProfileOperations.GetUserProfileByIdAsync("xO3SEJSVZN").Result;
                LinkedInProfile profileByPublicUrl = linkedIn.ProfileOperations.GetUserProfileByPublicUrlAsync("http://www.linkedin.com/in/bbaia").Result;
                LinkedInProfiles connections = linkedIn.ConnectionOperations.GetConnectionsAsync().Result;
                NetworkStatistics statistics = linkedIn.ConnectionOperations.GetNetworkStatisticsAsync().Result;
*/ 
                // Consume LinkedIn endpoints that are not covered by the API binding
/*
                string stringResult = linkedIn.RestOperations.GetForObjectAsync<string>("company-search?keywords=SpringSource&format=json").Result;
                JsonValue jsonResult = linkedIn.RestOperations.GetForObjectAsync<JsonValue>("job-search?job-title=LinkedIn&country-code=FR&format=json").Result;
*/
            }
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                    {
                        // TODO: Update after error handler implementation
                        if (ex is Spring.Rest.Client.HttpResponseException)
                        {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(((Spring.Rest.Client.HttpResponseException)ex).GetResponseBodyAsString());
                            return true;
                        }
                        return false;
                    });
            }
#else
                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                OAuthToken oauthToken = linkedInServiceProvider.OAuthOperations.FetchRequestToken("oob", null);
                Console.WriteLine("Done");

                string authenticateUrl = linkedInServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from LinkedIn authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = linkedInServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null);
                Console.WriteLine("Done");

                /* API */

                ILinkedIn linkedIn = linkedInServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

                LinkedInProfile profile = linkedIn.ProfileOperations.GetUserProfile();
                Console.WriteLine("Authenticated user is " + profile.FirstName + " " + profile.LastName);

                // Use step by step debugging             
/*
                LinkedInProfile profileById = linkedIn.ProfileOperations.GetUserProfileById("xO3SEJSVZN");
                LinkedInProfile profileByPublicUrl = linkedIn.ProfileOperations.GetUserProfileByPublicUrl("http://www.linkedin.com/in/bbaia");
                LinkedInProfiles connections = linkedIn.ConnectionOperations.GetConnections();
                NetworkStatistics statistics = linkedIn.ConnectionOperations.GetNetworkStatistics();
*/
                // Consume LinkedIn endpoints that are not covered by the API binding
/*
                string stringResult = linkedIn.RestOperations.GetForObject<string>("company-search?keywords=SpringSource&format=json");
                JsonValue jsonResult = linkedIn.RestOperations.GetForObject<JsonValue>("job-search?job-title=LinkedIn&country-code=FR&format=json");
*/
            }
		private static void Main(string[] args)
		{
			try
			{
				var geeklistServiceProvider = new GeeklistServiceProvider(GeeklistApiKey, GeeklistApiSecret);

				/* OAuth 'dance' */

				// Authentication using Out-of-band/PIN Code Authentication
				Console.Write("Getting request token...");
				var oauthToken = geeklistServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
				Console.WriteLine("Done");

				var authenticateUrl = geeklistServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
				Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
				Process.Start(authenticateUrl);
				Console.WriteLine("Enter PIN Code from Geeklist authorization page:");
				var pinCode = Console.ReadLine();

				Console.Write("Getting access token...");
				var requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
				var oauthAccessToken = geeklistServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
				Console.WriteLine("Done");

				/* API */

				var geeklist = geeklistServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);

				geeklist.UserOperations.GetUserAsync()
					.ContinueWith(task => Console.WriteLine("Username: "******"Activities: " + task.Result.Activities.Count));

				geeklist.CardOperations.GetUserCardsAsync()
					.ContinueWith(task => Console.WriteLine("Cards: " + task.Result.CardDetails.TotalCards));

				geeklist.FollowerOperations.GetUserFollowersAsync()
					.ContinueWith(task => Console.WriteLine("Followers: " + task.Result.FollowersDetails.TotalFollowers));

				geeklist.FollowingOperations.GetUserFollowingAsync()
					.ContinueWith(task => Console.WriteLine("Following: " + task.Result.FollowingDetails.TotalFollowing));

				geeklist.MicroOperations.GetUserMicrosAsync()
					.ContinueWith(task => Console.WriteLine("Micros: " + task.Result.MicrosDetails.TotalMicros));
			}
			catch (AggregateException ae)
			{
				ae.Handle(ex =>
				{
				    if (ex is GeeklistApiException)
				    {
				        Console.WriteLine(ex.Message);
				        return true;
				    }
				    return false;
				});
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex);
			}
			finally
			{
				Console.WriteLine("--- hit <return> to quit ---");
				Console.ReadLine();
			}
		}
 /// <summary>
 /// Asynchronously exchange the authorized request token for an access token.
 /// </summary>
 /// <param name="requestToken">
 /// An authorized request token and verifier. The verifier will be ignored for OAuth 1.0 providers
 /// </param>
 /// <param name="additionalParameters">
 /// Any additional query parameters to be sent when fetching the access token.
 /// </param>
 /// <param name="operationCompleted">
 /// The <code>Action&lt;T&gt;</code> to perform when the asynchronous request completes. 
 /// Provides the access token.
 /// </param>
 /// <returns>
 /// A <see cref="RestOperationCanceler"/> instance that allows to cancel the asynchronous operation.
 /// </returns>
 public RestOperationCanceler ExchangeForAccessTokenAsync(AuthorizedRequestToken requestToken, NameValueCollection additionalParameters, Action<RestOperationCompletedEventArgs<OAuthToken>> operationCompleted)
 {
     IDictionary<string, string> tokenParameters = new Dictionary<string, string>(2);
     tokenParameters.Add("oauth_token", requestToken.Value);
     if (version == OAuth1Version.Core10a)
     {
         tokenParameters.Add("oauth_verifier", requestToken.Verifier);
     }
     HttpEntity request = CreateExchangeForTokenRequest(this.accessTokenUrl, tokenParameters, additionalParameters, requestToken.Secret);
     return this.restTemplate.PostForObjectAsync<NameValueCollection>(this.accessTokenUrl, request,
         r =>
         {
             if (r.Error == null)
             {
                 OAuthToken token = this.CreateOAuthToken(r.Response["oauth_token"], r.Response["oauth_token_secret"], r.Response);
                 operationCompleted(new RestOperationCompletedEventArgs<OAuthToken>(token, null, false, r.UserState));
             }
             else
             {
                 operationCompleted(new RestOperationCompletedEventArgs<OAuthToken>(null, r.Error, r.Cancelled, r.UserState));
             }
         });
 }
        static void Main(string[] args)
        {
            try
            {
                TwitterServiceProvider twitterServiceProvider = new TwitterServiceProvider(TwitterConsumerKey, TwitterConsumerSecret);

#if NET_4_0
                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                OAuthToken oauthToken = twitterServiceProvider.OAuthOperations.FetchRequestTokenAsync("oob", null).Result;
                Console.WriteLine("Done");

                string authenticateUrl = twitterServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from Twitter authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = twitterServiceProvider.OAuthOperations.ExchangeForAccessTokenAsync(requestToken, null).Result;
                Console.WriteLine("Done");

                /* API */

                ITwitter twitter = twitterServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                //ITwitter twitter = new TwitterTemplate();

                twitter.UserOperations.GetUserProfileAsync("brbaia")
                    .ContinueWith(task => Console.WriteLine("brbaia is " + task.Result.Name));

                // Use step by step debugging
/*
                Tweet tweet = twitter.TimelineOperations.UpdateStatusAsync(
                    "Hi from #Spring.NET Social Twitter! http://bit.ly/x2rvlC", new AssemblyResource("Image.png", typeof(Program))).Result;
                twitter.UserOperations.GetUserProfileImageAsync("twitter", ImageSize.Original)
                    .ContinueWith(task =>
                    {
                        // Save file to "C:\twitter.jpg"
                        using (FileStream fileStream = new FileStream(@"C:\twitter.jpg", FileMode.Create))
                        {
                            fileStream.Write(task.Result, 0, task.Result.Length);
                        }
                    });
                SearchResults searchResults = twitter.SearchOperations.SearchAsync("Portugal").Result;
                CursoredList<UserList> s2Lists = twitter.ListOperations.GetListsAsync("SpringSource").Result;
                IList<Place> places = twitter.GeoOperations.SearchAsync(33.050278, -96.745833).Result;
                bool friendshipExists = twitter.FriendOperations.FriendshipExistsAsync("brbaia", "sbohlen").Result;
                IList<DirectMessage> myDmReceived = twitter.DirectMessageOperations.GetDirectMessagesReceivedAsync().Result;
                bool isBlocking = twitter.BlockOperations.IsBlockingAsync("brbaia").Result;
*/
            }
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                    {
                        if (ex is TwitterApiException)
                        {
                            Console.WriteLine(ex.Message);
                            return true;
                        }
                        return false;
                    });
            }
#else
                /* OAuth 'dance' */

                // Authentication using Out-of-band/PIN Code Authentication
                Console.Write("Getting request token...");
                OAuthToken oauthToken = twitterServiceProvider.OAuthOperations.FetchRequestToken("oob", null);
                Console.WriteLine("Done");

                string authenticateUrl = twitterServiceProvider.OAuthOperations.BuildAuthorizeUrl(oauthToken.Value, null);
                Console.WriteLine("Redirect user for authentication: " + authenticateUrl);
                Process.Start(authenticateUrl);
                Console.WriteLine("Enter PIN Code from Twitter authorization page:");
                string pinCode = Console.ReadLine();

                Console.Write("Getting access token...");
                AuthorizedRequestToken requestToken = new AuthorizedRequestToken(oauthToken, pinCode);
                OAuthToken oauthAccessToken = twitterServiceProvider.OAuthOperations.ExchangeForAccessToken(requestToken, null);
                Console.WriteLine("Done");

                /* API */

                ITwitter twitter = twitterServiceProvider.GetApi(oauthAccessToken.Value, oauthAccessToken.Secret);
                //ITwitter twitter = new TwitterTemplate();

                TwitterProfile profile = twitter.UserOperations.GetUserProfile("brbaia");
                Console.WriteLine("brbaia is " + profile.Name);

                // Use step by step debugging
/*
                Tweet tweet = twitter.TimelineOperations.UpdateStatus(
                    "Hi from #Spring.NET Social Twitter! http://bit.ly/x2rvlC", new AssemblyResource("Image.png", typeof(Program)));
                twitter.UserOperations.GetUserProfileImageAsync("twitter", ImageSize.Original, 
                    r =>
                    {
                        // Save file to "C:\twitter.jpg"
                        using (FileStream fileStream = new FileStream(@"C:\twitter.jpg", FileMode.Create))
                        {
                            fileStream.Write(r.Response, 0, r.Response.Length);
                        }
                    });
                SearchResults searchResults = twitter.SearchOperations.Search("Portugal");
                CursoredList<UserList> s2Lists = twitter.ListOperations.GetLists("SpringSource");
                IList<Place> places = twitter.GeoOperations.Search(33.050278, -96.745833);
                bool friendshipExists = twitter.FriendOperations.FriendshipExists("brbaia", "sbohlen");
                IList<DirectMessage> myDmReceived = twitter.DirectMessageOperations.GetDirectMessagesReceived();
                bool isBlocking = twitter.BlockOperations.IsBlocking("brbaia");
*/
            }
 /// <summary>
 /// Exchange the authorized request token for an access token.
 /// </summary>
 /// <param name="requestToken">
 /// An authorized request token and verifier. The verifier will be ignored for OAuth 1.0 providers.
 /// </param>
 /// <param name="additionalParameters">
 /// Any additional query parameters to be sent when fetching the access token.
 /// </param>
 /// <returns>The access token.</returns>
 public OAuthToken ExchangeForAccessToken(AuthorizedRequestToken requestToken, NameValueCollection additionalParameters)
 {
     IDictionary<string, string> tokenParameters = new Dictionary<string, string>(2);
     tokenParameters.Add("oauth_token", requestToken.Value);
     if (version == OAuth1Version.Core10a)
     {
         tokenParameters.Add("oauth_verifier", requestToken.Verifier);
     }
     HttpEntity request = CreateExchangeForTokenRequest(this.accessTokenUrl, tokenParameters, additionalParameters, requestToken.Secret);
     NameValueCollection response = this.restTemplate.PostForObject<NameValueCollection>(this.accessTokenUrl, request);
     return this.CreateOAuthToken(response["oauth_token"], response["oauth_token_secret"], response);
 }