问题
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