Ejemplo n.º 1
0
        public ActionResult Index()
        {
            string url = "";
            string xml = "";
            oAuthTwitter oAuth = new oAuthTwitter();

            if (Request["oauth_token"] == null)
            {
                //Redirect the user to Twitter for authorization.
                //Using oauth_callback for local testing.
                oAuth.CallBackUrl = "http://localhost/MvcApplication1/Twitter";
                Response.Redirect(oAuth.AuthorizationLinkGet());
            }
            else
            {
                //Get the access token and secret.
                oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);

                if (oAuth.TokenSecret.Length > 0)
                {
                    //We now have the credentials, so make a call to the Twitter API.
                    url = "http://twitter.com/account/verify_credentials.xml";
                    xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
                    //apiResponse.InnerHtml = Server.HtmlEncode(xml);
                    String parametroApertura = "<screen_name>";
                    String parametroCierre = "</screen_name>";
                    String xmlParseado = parsear(xml, parametroApertura, parametroCierre);

                    ViewData["XML"] = xmlParseado;
                    ViewData["login"] = "******";
                    Session.Timeout = 5;
                    Session["data"] = xmlParseado;
                    Session["tokken"] =oAuth.TokenSecret;
                    //POST Test
                    IRepositorioPersona<Persona> repo = new PersonaRepositorio();
                    Persona p = repo.GetById(xmlParseado);
                    if (p == null)
                    {
                        url = "http://twitter.com/statuses/update.xml";
                        xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url,"status=" +oAuth.UrlEncode("Yo, ya me uni a la red @TwistedUCAB ... que esperas Unete! y comparte tus viajes tambien."));
                    }

                //apiResponse.InnerHtml = Server.HtmlEncode(xml);
                    XmlSiteMapProvider my = new XmlSiteMapProvider();
                    return RedirectToAction("Verificar", "Persona");
                }
            }
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 2
0
        public ActionResult CerrarViaje()
        {
            string url = "";
            string xml = "";
            oAuthTwitter oAuth = new oAuthTwitter();

            if (Request["oauth_token"] == null)
            {
                //Redirect the user to Twitter for authorization.
                //Using oauth_callback for local testing.
                oAuth.CallBackUrl = "http://localhost/MvcApplication1/Twitter/CerrarViaje";
                Response.Redirect(oAuth.AuthorizationLinkGet());
            }
            else
            {
                //Get the access token and secret.
                oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
                if (oAuth.TokenSecret.Length > 0)
                {
                    //We now have the credentials, so make a call to the Twitter API.
                    url = "http://twitter.com/account/verify_credentials.xml";
                    xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
                    //apiResponse.InnerHtml = Server.HtmlEncode(xml);
                    String parametroApertura = "<screen_name>";
                    String parametroCierre = "</screen_name>";
                    String xmlParseado = parsear(xml, parametroApertura, parametroCierre);

                    ViewData["XML"] = xmlParseado;
                    ViewData["login"] = "******";
                    Session.Timeout = 5;
                    Session["data"] = xmlParseado;
                    //POST Test
                    url = "http://twitter.com/statuses/update.xml";
                    String twt = Session["twt"] as string;
                    xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode(twt));

                    return RedirectToAction("Pdf", "Pdf");
                }
            }
            return RedirectToAction("Pdf", "Pdf");
        }
Ejemplo n.º 3
0
        public string WebRequest(oAuthTwitter.Method method, string url, string postData)
        {
            HttpWebRequest webRequest = null;
            StreamWriter requestWriter = null;
            string responseData = "";

            webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
            webRequest.Method = method.ToString();
            webRequest.ServicePoint.Expect100Continue = false;
            //webRequest.UserAgent  = "Identify your application please.";
            //webRequest.Timeout = 20000;

            if (method == oAuthTwitter.Method.POST || method == oAuthTwitter.Method.DELETE)
            {
                webRequest.ContentType = "application/x-www-form-urlencoded";

                //POST the data.
                requestWriter = new StreamWriter(webRequest.GetRequestStream());
                try
                {
                    requestWriter.Write(postData);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    requestWriter.Close();
                    requestWriter = null;
                }
            }

            responseData = WebResponseGet(webRequest);

            webRequest = null;

            return responseData;
        }