This project has moved and is read-only. For the latest updates, please go here.

Error 401 Unauhtorized LinqToTiwtter API

Aug 10, 2012 at 4:10 PM

Hi ! i tried to fallow the demo webformrtimeline so I wrote this code for a DotNetNuke Module  when a push the bottom btnAutorizar for beginauthorization always the response  is Error 401 Unauhtorized .  there are the configuration that i put into the settings of my module. 

ConsumerKey: lcgG6BXQpwQtHSzwqWA

ConsumerSecret: 6MoV8PlLBktgVaAP5ezDYEHGMKcHGEDe8eDuk5mpas

and my aplicattion in twitter call dnnPrueba

What is my mistake in the code??, what more i need?  please help me! and sorry for my English!


public partial class ViewTwitterAndrea : PortalModuleBase    {         

private ConfiguracionTwitterAndrea configuracion;       

private WebAuthorizer wbAuthorizer;            

protected void Page_Load(object sender, EventArgs e)        {           

try            {                   

configuracion = new ConfiguracionTwitterAndrea(this.TabModuleId);                   

string consumerKey = configuracion.ConsumerKey;                   

string consumerSecret = configuracion.ConsumerSecret;                                        

     if (string.IsNullOrEmpty(consumerKey) || string.IsNullOrEmpty(consumerSecret))                    {                        this.mvTwitterAndrea.SetActiveView(this.vwConfiguracion);                    }                    else {                      

         IOAuthCredentials objCredenciales = new SessionStateCredentials();                          

          if (objCredenciales.ConsumerKey == null || objCredenciales.ConsumerSecret == null)                            {                               

                      objCredenciales.ConsumerKey = configuracion.ConsumerKey;                                                           objCredenciales.ConsumerSecret = configuracion.ConsumerSecret;   


            wbAuthorizer = new WebAuthorizer {                                


                         PerformRedirect = authUrl => Response.Redirect(authUrl)      };                               if(!Page.IsPostBack){                         



if(string.IsNullOrEmpty(objCredenciales.ConsumerKey) || string.IsNullOrEmpty(objCredenciales.ConsumerSecret)){                                lblRegistrado.Text = "No estas autorizado aun";           

      btnAutorizar.Visible = true; 

       btnTweets.Visible = false;

 }else if(wbAuthorizer.IsAuthorized){                 

              lblRegistrado.Text = "Estas Autorizado.";     

              btnAutorizar.Visible = false;                           

             btnTweets.Visible = true;                 


         this.mvTwitterAndrea.SetActiveView(vwAutorizacion);                                        }            }              catch (Exception ex)            {                Exceptions.ProcessModuleLoadException(this, ex);            }       


        protected void BtnEnviar_Click(object sender, EventArgs e)        {            ComunicacionTwitter objTwitter = new ComunicacionTwitter(this.TabModuleId);   

 Status objStatus= objTwitter.ActualizarEstado(wbAuthorizer, this.txtEstado.Text);

        protected void btnAutorizar_Click(object sender, EventArgs e)        {            try {               


  }catch(Exception ex){
            }                    }

protected void btnTweets_Click(object sender, EventArgs e)        {           

try  {       

    wbAuthorizer = new WebAuthorizer    {               

   Credentials = new SessionStateCredentials()     };

  ComunicacionTwitter objTwitter = new ComunicacionTwitter(this.TabModuleId);               

var UltimosTweets = objTwitter.getHomeTimeLine(wbAuthorizer, intCantidadTweets);

   foreach (var Tweet in UltimosTweets)                {                   

this.spnTweets.InnerHtml =    "<div class='twitterTweet'>" +    

"<div class='twitterUsuario'>Usuario " + Tweet.ScreenName + "</div>" + 

"<div class='twitterContenido'>" + Tweet.Text + "</div>" + 

"<div class='twitterFecha'>" + Tweet.CreatedAt + "</div>" +                   



  this.mvTwitterAndrea.SetActiveView(this.vwTweets);            }catch(Exception ex){    }     



********************** And I have another class

Class ConfiguracionTwitter{

 public ConfiguracionTwitter(){} 

public IEnumerable<Status> getHomeTimeLine(WebAuthorizer auth,int intCantidadTweets) {            twitterContexto= new TwitterContext(auth);           

var tweets =        

 (from tweet in twitterContexto.Status                       

 where tweet.Type == StatusType.Home                        

 select tweet).Take(intCantidadTweets).ToList();           

return tweets;        }


Aug 16, 2012 at 11:20 PM


The 401 Unauthorized means that Twitter is unable to authorize your application. This is a common problem when writing your first Twitter application and it can happen for multiple reasons.  I've created a FAQ that has tips on how to resolve this problem:

You should get the sample application on this site working first because it is working code and will help resolve the 401 errors.  The on the following page should be a good place to start:

BTW, you posted your credentials here, which makes your application insecure.  You should visit your application site on the Twitter developers page ( and re-generate your keys.