LinqToTwitter Authorization Help

泪湿孤枕 提交于 2019-12-10 17:03:34

问题


I am using LinqToTwitter (http://linqtotwitter.codeplex.com/), but I haven't a clue about where to start with the authorization thing. So far I have this:

var oAuth = new OAuthTwitter ();
oAuth.OAuthConsumerKey ="mykey";
oAuth.OAuthConsumerSecret ="mySecret" ;

string loginUrl = oAuth.AuthorizationLinkGet( 
   "https://api.twitter.com/oauth/request_token" , 
   "https://api.twitter.com/oauth/authorize", "", true ); 
var twitterCtx = new TwitterContext ();

//return Redirect(loginUrl); //(ASP.NET) 

var publicTweets = from tweet in twitterCtx.Status 
where tweet.Type == StatusType .Public 
select tweet; publicTweets.ToList().ForEach(tweet => AddItem(tweet.User.Name, tweet.Text)); 

I just want the quickest, simplest way of authorizing the desktop app. I couldn't find much documentation.

FYI - This won't be for multiple users... I will have a single user name and password that will always be used... if that helps make it simpler.

Many thanks


回答1:


Here is a working example:

var auth = new SingleUserAuthorizer
{
    Credentials = new InMemoryCredentials
    {
        ConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"],
        ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"],
        OAuthToken = ConfigurationManager.AppSettings["TwitterAccessToken"],
        AccessToken = ConfigurationManager.AppSettings["TwitterAccessTokenSecret"]
    }
};

using (var db = new TwitterContext(auth))
{
    string search = Server.UrlEncode(txtSearch.Text.Trim());

    var list = db.User
              .Where(u =>
                        u.Type == UserType.Search &&
                        u.Query == searchExpression &&
                        u.Page == 1
                        )
              .ToList();  
}


来源:https://stackoverflow.com/questions/7020650/linqtotwitter-authorization-help

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