view Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs @ 107:1ee5711256db

Utilizando Twitterizer en adapter a Twitter
author Nelo@Kenia.neluz.int
date Tue, 07 Jun 2011 21:03:56 -0300
parents db4b1e2cae49
children a456eb519e23
line wrap: on
line source

using System;
using System.Configuration;
using Twitterizer;

namespace AltNetHispano.Agendas.Twitter
{
	public class OAuthTwitter
	{
		private string ConsumerKey
		{
			get { return ConfigurationManager.AppSettings["consumerKey"]; }
		}

		private string ConsumerSecret
		{
			get { return ConfigurationManager.AppSettings["consumerSecret"]; }
		}

		public Uri AuthorizationLinkGet(string callbackAddress)
		{
			// Obtain a request token
			OAuthTokenResponse requestToken = OAuthUtility.GetRequestToken(ConsumerKey, ConsumerSecret, callbackAddress);

			// Direct or instruct the user to the following address:
			Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token);

			return authorizationUri;
		}

		public string AccessTokenGet(string requestToken, string verifier)
		{
			OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken, verifier);
			if (accessToken!=null)
			{
				var tokens = new OAuthTokens
				             	{
				             		AccessToken = accessToken.Token,
				             		AccessTokenSecret = accessToken.TokenSecret,
				             		ConsumerKey = ConsumerKey,
				             		ConsumerSecret = ConsumerSecret
				             	};

				TwitterResponse<TwitterUser> showUserResponse = TwitterUser.Show(tokens, accessToken.UserId);
				if (showUserResponse.Result == RequestResult.Success)
					return showUserResponse.Content;
				return showUserResponse.ErrorMessage;
			}
			return string.Empty;
		}
	}
}