Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs @ 111:90ce239cfa6d
Tests sobre el publicador de twitter, cada track se pulica solo una vez
author | Nelo@Kenia.neluz.int |
---|---|
date | Wed, 08 Jun 2011 08:40:04 -0300 |
parents | a456eb519e23 |
children | 0bca45e1e664 |
comparison
equal
deleted
inserted
replaced
110:a456eb519e23 | 111:90ce239cfa6d |
---|---|
1 using System; | 1 using System; |
2 using System.Configuration; | 2 using System.Configuration; |
3 using Twitterizer; | |
4 | 3 |
5 namespace AltNetHispano.Agendas.Twitter | 4 namespace AltNetHispano.Agendas.Twitter |
6 { | 5 { |
7 public class OAuthTwitter | 6 public class OAuthTwitter |
8 { | 7 { |
8 private readonly ITwitterAdapter _twitterAdapter; | |
9 | |
10 public OAuthTwitter() | |
11 { | |
12 _twitterAdapter = new TwitterAdapter(); | |
13 } | |
14 | |
15 public OAuthTwitter(ITwitterAdapter twitterAdapter) | |
16 { | |
17 _twitterAdapter = twitterAdapter; | |
18 } | |
19 | |
9 private string ConsumerKey | 20 private string ConsumerKey |
10 { | 21 { |
11 get { return ConfigurationManager.AppSettings["consumerKeyAppSignIn"]; } | 22 get { return ConfigurationManager.AppSettings["consumerKeyAppSignIn"]; } |
12 } | 23 } |
13 | 24 |
16 get { return ConfigurationManager.AppSettings["consumerSecretAppSignIn"]; } | 27 get { return ConfigurationManager.AppSettings["consumerSecretAppSignIn"]; } |
17 } | 28 } |
18 | 29 |
19 public Uri AuthorizationLinkGet(string callbackAddress) | 30 public Uri AuthorizationLinkGet(string callbackAddress) |
20 { | 31 { |
21 // Obtain a request token | 32 var request = _twitterAdapter.BuildAuthorizationUri(ConsumerKey, ConsumerSecret, callbackAddress); |
22 OAuthTokenResponse requestToken = OAuthUtility.GetRequestToken(ConsumerKey, ConsumerSecret, callbackAddress); | 33 return request; |
23 | |
24 // Direct or instruct the user to the following address: | |
25 Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token); | |
26 | |
27 return authorizationUri; | |
28 } | 34 } |
29 | 35 |
30 public string AccessTokenGet(string requestToken, string verifier) | 36 public string AccessTokenGet(string requestToken, string verifier) |
31 { | 37 { |
32 OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken, verifier); | 38 return _twitterAdapter.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken, verifier); |
33 | |
34 if (accessToken!=null) | |
35 { | |
36 var tokens = new OAuthTokens | |
37 { | |
38 AccessToken = accessToken.Token, | |
39 AccessTokenSecret = accessToken.TokenSecret, | |
40 ConsumerKey = ConsumerKey, | |
41 ConsumerSecret = ConsumerSecret | |
42 }; | |
43 | |
44 TwitterResponse<TwitterUser> showUserResponse = TwitterUser.Show(tokens, accessToken.UserId); | |
45 if (showUserResponse.Result == RequestResult.Success) | |
46 return showUserResponse.Content; | |
47 return showUserResponse.ErrorMessage; | |
48 } | |
49 return string.Empty; | |
50 } | 39 } |
51 } | 40 } |
52 } | 41 } |