本文介绍了LinqToTwitter授权帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LinqToTwitter(HTTP://linqtotwitter.$c$cplex.com/),但
我已经不是在哪里与授权的事情,开始的线索。到目前为止,我有这样的:

I am using LinqToTwitter (http://linqtotwitter.codeplex.com/), butI 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.

非常感谢

推荐答案

下面是一个工作的例子:

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

这篇关于LinqToTwitter授权帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 11:06