LinqToTwitter 授权帮助

发布于 2024-11-28 21:44:45 字数 772 浏览 1 评论 0原文

我正在使用 LinqToTwitter (http://linqtotwitter.codeplex.com/),但是 我不知道从哪里开始授权的事情。到目前为止,我的想法是:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱果果 2024-12-05 21:44:45

这是一个工作示例:

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

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();  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文