当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc 4 - LinqToTwitter - IsAuthorized always returns false for ApplicationOnlyAuthorizer

问题描述:

I have an MVC4 web application that uses LinqToTwitter to display Tweets when a user's profile page is visited, if they have a Twitter handle.

For this I use ApplicationOnlyAuthorizer:

var auth = new ApplicationOnlyAuthorizer

{

Credentials = new InMemoryCredentials

{

ConsumerKey = "twitterConsumerKey",

ConsumerSecret = "twitterConsumerSecret"

}

};

auth.Authorize();

My problem is that I have found that auth.IsAuthorized always returns false, even when I have call Authorize() and am successfully able to make calls to Twitter. And also, I have found that if I call Authorize() in every call made to Twitter, that an unhandled exception is thrown if I repeat the call enough times.

It seems quite important that I am able to know if auth is authorized before I make the call to Twitter. For now, I have put in a quick fix where I store my own IsAuthorized Session variable - but am not sure how reliable this is, because the Session variable could outlive the actual authentication itself?

Any advice on this would be appreciated.

网友答案:

The first time you authorize, Twitter will return a bearer token. After Authorize, you can grab this from the auth.BearerToken property. On subsequent calls, you can re-use the same bearer token. The bearer token doesn't expire, unless you invalidate it. Twitter's recommendation is that you use the bearer token for about 15 minutes and then re-authorize after that.

分享给朋友:
您可能感兴趣的文章:
随机阅读: