Mercurial > altnet-hispano
diff Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs @ 107:1ee5711256db
Utilizando Twitterizer en adapter a Twitter
author | Nelo@Kenia.neluz.int |
---|---|
date | Tue, 07 Jun 2011 21:03:56 -0300 |
parents | 1eb5a0e531bf |
children | 0bca45e1e664 |
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs Sat Jun 04 19:41:40 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/AccountController.cs Tue Jun 07 21:03:56 2011 -0300 @@ -62,27 +62,19 @@ if (Request["oauth_token"] == null) { - //Redirect the user to Twitter for authorization. - //Using oauth_callback for local testing. var action = Url.Action("TwitterLogOn"); var url = Request.Url.Scheme + "://" + Request.Url.Host + (Request.Url.Port != 80 ? ":" + Request.Url.Port : string.Empty) + action; - oAuth.CallBackUrl = url; - Response.Redirect(oAuth.AuthorizationLinkGet()); + Response.Redirect(oAuth.AuthorizationLinkGet(url).ToString()); } else { - //Get the access token and secret. - oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]); - if (oAuth.TokenSecret.Length > 0) + var response = oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]); + if (response.Length > 0) { - //We now have the credentials, so make a call to the Twitter API. - const string url = "http://twitter.com/account/verify_credentials.xml"; - string xml = oAuth.OAuthWebRequest(OAuthTwitter.Method.GET, url, String.Empty); - - var username = GetXmlContent(xml, "screen_name"); - var nombre = GetXmlContent(xml, "name"); + var username = GetResponseContent(response, "screen_name"); + var nombre = GetResponseContent(response, "name"); var personaService = AgendaFactory.GetPersonaService(); if (personaService.Validate(IdentityProviderEnum.Twitter, username, nombre)) @@ -91,34 +83,28 @@ return RedirectToAction("Index", "Home"); } ModelState.AddModelError("", "The user name or password provided is incorrect."); - - - //POST Test - //url = "http://twitter.com/statuses/update.xml"; - //xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode("Hello @swhitley - Testing the .NET oAuth API")); - //apiResponse.InnerHtml = Server.HtmlEncode(xml); } } return RedirectToAction("LogOn"); } - private static string GetXmlContent(string xml, string tagName) - { - var tagStart = "<" + tagName + ">"; - var tagEnd = "</" + tagName + ">"; + private static string GetResponseContent(string response, string tagName) + { + var tagStart = "\"" + tagName + "\":"; + var tagEnd = ","; - var start = xml.IndexOf(tagStart)+tagStart.Length; - if (start>tagStart.Length) + var start = response.IndexOf(tagStart) + tagStart.Length; + if (start > tagStart.Length) { - var end = xml.IndexOf(tagEnd, start); - if (end>0) + var end = response.IndexOf(tagEnd, start); + if (end > 0) { - return xml.Substring(start, end - start); + return response.Substring(start + 1, end - start - 2); } } - return string.Empty; - } + return string.Empty; + } // ************************************** // URL: /Account/LogOff