view Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs @ 110:a456eb519e23

Lanzando twitts desde el sitio con la cuenta de AltNetHispanoDESA
author Nelo@Kenia.neluz.int
date Wed, 08 Jun 2011 07:33:14 -0300
parents 1ee5711256db
children 90ce239cfa6d
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["consumerKeyAppSignIn"]; }
		}

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

		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;
		}
	}
}