LinqToTwitter - IsAuthorized always returns false for ApplicationOnlyAuthorizer

时光毁灭记忆、已成空白 提交于 2019-12-10 00:19:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16520278/linqtotwitter-isauthorized-always-returns-false-for-applicationonlyauthorizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!