2012-08-10 85 views
0

我遵循linqtotiwwter.codeplex.com 的演示中,我试图休耕演示webformrtimeline所以我写了这个代码的DotNetNuke的模块时推底部btnAutorizar为beginauthorization总是响应错误401 Unauhtorized。有配置,我把我的模块的设置。错误401不Unauhtorized LinqToTiwtter API

ConsumerKey:lcgG6BXQpwQtHSzwqWA ConsumerSecret:6MoV8PlLBktgVaAP5ezDYEHGMKcHGEDe8eDuk5mpas 和我在Twitter上呼吁dnnPrueba

什么是我的代码?错误aplicattion,更多的我需要什么?请帮帮我!抱歉我的英语!


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 {         
Credentials=objCredenciales, 
PerformRedirect = authUrl => Response.Redirect(authUrl)  };         
if(!Page.IsPostBack){       
wbAuthorizer.CompleteAuthorization(Request.Url);               
} 
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 {    
wbAuthorizer.BeginAuthorization(Request.Url);   
}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>" +     
"</div>";    
} 
this.mvTwitterAndrea.SetActiveView(this.vwTweets);    
}catch(Exception ex){ }  
} 
} 
} 

** * ** * ** * *我有另一个类

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

回答

0

“401未授权” 意味着你应用程序无法使用Twitter进行身份验证。有很多事情,可能会导致一个401我已经编制了一个常见问题,会给你的事情的清单来检查:

http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation

BTW,发布您的OAuth键值,使您的应用程序是不安全的。您应该尽快在Twitter页面上访问您的应用程序,并生成一组新的密钥。

Joe

+0

Ok Joe Mayo在这一刻,我正在改变OAuth密钥! – 2012-08-10 21:24:57